Arithmetic Mean in C programming

Arithmetic mean is the sum of a collection of numbers divided by the number of numbers in the collection. It is one of the most commonly used measures of central tendency in statistics and mathematics.

Syntax

mean = (sum of all numbers) / (count of numbers)

Basic Properties of Arithmetic Mean

  • If each observation is increased by p, the mean increases by p.
  • If each observation is decreased by p, the mean decreases by p.
  • If each observation is multiplied by p, the mean is multiplied by p.
  • If each observation is divided by p, the mean is divided by p.

Method 1: Direct Arithmetic Mean

Given an array of numbers, we calculate the mean by summing all elements and dividing by the count −

#include <stdio.h>

int main() {
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    int n = 9;
    int sum = 0;
    
    for (int i = 0; i < n; i++) {
        sum += arr[i];
    }
    
    float mean = (float)sum / n;
    printf("Arithmetic Mean = %.2f<br>", mean);
    
    return 0;
}
Arithmetic Mean = 5.00

Method 2: Arithmetic Means in Progression

To find N arithmetic means between two numbers X and Y, we use the formula for arithmetic progression where the common difference d = (Y - X) / (N + 1) −

#include <stdio.h>

int main() {
    int X = 22, Y = 34, N = 5;
    float d = (float)(Y - X) / (N + 1);
    
    printf("N arithmetic means between %d and %d: ", X, Y);
    for (int i = 1; i <= N; i++) {
        printf("%.0f ", (X + i * d));
    }
    printf("<br>");
    
    return 0;
}
N arithmetic means between 22 and 34: 24 26 28 30 32 

Key Points

  • Always use float or double for accurate division results.
  • The arithmetic progression formula: Y = X + (N+1)d, where d is the common difference.
  • Time complexity is O(n) for calculating mean of n numbers.

Conclusion

Arithmetic mean is fundamental in C programming for statistical calculations. Whether calculating a simple average or finding means in arithmetic progression, proper data type handling ensures accurate results.

Updated on: 2026-03-15T11:31:13+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements