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: