In this c programming example we will learn how to calculate sum of an integer array
#include <stdio.h>
int main() { int n; printf("Enter Array count "); scanf("%d",&n); int array[n]; for(int k=0;k<n;k++) { scanf("%d",&array[k]); } int sum, loop;
sum = 0; for(loop = n-1; loop >= 0; loop--) { sum = sum + array[loop]; }
printf("Sum of array is %d.", sum);
return 0; }
Enter Array count 5 1 1 1 1 1 Sum of array is 5.
c beginner programs