C Program to find the sum of array elements


In this program, You will learn how to find sum of array elements in c.


for (int i = 0; i < 10; i++) {
     s = s + arr[i]; 
}

Example: How to find the sum of array elements in c

#include<stdio.h>
int main() {

   int arr[10], i, s = 0;

   printf("Enter 5 numbers:");
   for (i = 0; i < 5; i++) {
       scanf("%d", &arr[i]);
   }

   for (i = 0; i < 5; i++) {
       s = s + arr[i];
   }
   printf("Sum is:%d", s);

   return 0;
}

Output:

Enter 5 numbers:10 20 30 40 50
Sum is:150