C Program to Calculate the Average of All the Elements Present in an Array - Source Code, Output & Execution Flow

C Program to Calculate the Average of All the Elements Present in an Array

This C program calculates the average of all elements in an array.

#include <stdio.h>
int main() {
    int a[] = {10, 20, 30, 40, 50};
    int i, sum = 0;
    float average;
    for (i = 0; i < 5; i++) sum += a[i];
    average = sum / 5.0f;
    printf("Average = %.2f
", average);
    return 0;
}
Average = 30.00

In this program, the input is read first when required, the core logic is applied step by step, and the final result is displayed using printf(). Follow the execution flow beside the code to understand how each statement contributes to the output.