sum of arrays

Sum of Arrays in C

#include <stdio.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5};
    int sum = 0;

    for (int i = 0; i < 5; i++) {
        sum += arr[i];
    }

    printf("The sum of the array elements is: %d", sum);

    return 0;
}
  1. Declaration and Initialization:
  2. An array of integers arr is declared and initialized with values {1, 2, 3, 4, 5}.
  3. A variable sum is initialized to 0 to store the sum of the array elements.

  4. Sum Calculation:

  5. A for loop is used to iterate through the array elements.
  6. The value of each element is added to the sum variable.

  7. Output:

  8. The sum of the array elements is printed using printf.