Program to find the sum of all n elements in an array in C-language
#include<stdio.h>
int main()
{
int i,a[10],n,sum=0;
printf("Enter the size limit maximum is 10\n");
scanf("%d",&n);
printf("Enter the array element\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf(" Sum of Array element is\n");
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
printf(" %d ",sum);
}
OUTPUT
Enter the size limit maximum is 10
4
Enter the array element
1
4
3
2
Sum of Array element is
10
Comments
Post a Comment