Write a program in C to find sum of all array elements.
#include<stdio.h> #include<conio.h> void main() { int a[50],i,sum=0,n; clrscr(); printf("Enter a number you want to inset in array:-"); scanf("%d",&n); printf("Enter %d no.:-",n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { sum=sum+a[i]; } printf(" Sum =%d",sum); getch(); }
Output:
0 Comments