1-Dimensional (1D) Array Program in C

One Dimensional Array C Program to Read Array Elements

#include<stdio.h>         //library or header file

main()        //main function from program start executing
{

int a[5];         //initialize array
int i,sum=0;           //intialize variable i and sum which we use in loop

printf("enter array elements on screen:\n");           //print message on screen

for(i=0;i<5;i++)
{

scanf("%d",&a[i]);  //take input from user a[0..4]

}

printf("\n");   //newline after printing message on screen

for(i=0;i<5;i++)
{

printf("Element are:%d\n",a[i]);   //print elements which user entered in array a[i]

}

for(i=0;i<5;i++)
{

sum=sum+a[i];    //loop to sum array element 

}

printf("\n");

printf("sum is:%d\n",sum);   //print sum

}   //main function end

Copyright © C Program | Java | OpenGL Programming | Hadoop at Computaholics