C Program to Find Sum and Average of Elements in an Array
Subject: PPS (Programming for Problem Solving)
Contributed By: Sanjay
Created At: February 3, 2025
Question:
Write a C Program to Find Sum and Average of Elements in an Array
Explanation Video:

Explanation:
We sum all elements and divide by the number of elements to find the average.
Source Code:
#include <stdio.h>
int main() {
int arr[] = {10, 20, 30, 40, 50};
int n = sizeof(arr) / sizeof(arr[0]);
int sum = 0;
for (int i = 0; i < n; i++)
sum += arr[i];
printf("Sum: %d, Average: %.2f\n", sum, (float)sum / n);
return 0;
}
Output:
Sum: 150, Average: 30.00