Arrays
Sum of Array Elements
Find the sum of all elements in an array.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Find the sum of all elements in an array.
#include <stdio.h>
int main() {
int n, sum = 0;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
for (int i = 0; i < n; i++) sum += arr[i];
printf("Sum = %d\n", sum);
return 0;
}
5
1 2 3 4 5
Sum = 15