Sum of all element of array data structure by R4R Team

Example-
array is {4,5,3,2,8}
Sum of all element is 22

program-

#include< stdio.h>
int main()
{
int a[100],n,i,sum=0;
printf("Number of element in array ?\n");
scanf("%d",&n);
printf("Enter %d number in array\n",n);
for(i=0;i< n;i++)
scanf("%d",&a[i]);
//Now calculate the sum
for(i=0;i< n;i++)
sum=sum+a[i];
printf("Sum of all number in array is %d",sum);
}


output-

Number of element in array ?
6
Enter 6 number in array
1 2 3 4 5 6
Sum of all number in array is 21

-In this program, we take a input in the array and try to sum up of elements of array.
-We run loop and add each elements of array to variable sum.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!