In this article, let’s learn some of the basic but essential C programs based on Mathematical Statistics

## 1. Write a program to find out the arithmetic mean of the following frequency distribution using the given formula.

x | 1 | 2 | 3 | 4 | 5 | 6 | 7 |

f | 5 | 9 | 12 | 17 | 14 | 10 | 6 |

The **Arithmetic Mean** of a set of observations is their sum divided by the number of observations. Let’s find out the arithmetic mean of the given frequency distribution with the C program.

When you execute the above program, the output will look like this as shown below:

```
COMPUTATION OF MEAN
X FREQUENCY FX
1 5 5
2 9 18
3 12 36
4 17 68
5 14 70
6 10 60
7 6 42
TOTAL FREQUENCY: 73.000000
TOTAL FX: 299.000000
ESTIMATE MEAN USING FORMULA: 4.095891
```

## 2. Write a program to calculate the arithmetic mean of the marks from the following table.

Marks | 0-10 | 10-20 | 20-30 | 30-40 | 40-50 | 50-60 |

No. of Students | 12 | 18 | 27 | 20 | 17 | 6 |

Let’s find out the arithmetic mean of the given frequency distribution with the C program.

When you execute the above program, the output will look like this as shown below:

```
Marks No. of Students (f) Mid-Point (x) FX
0-10 12 5 60
10-20 18 15 270
20-30 27 25 675
30-40 20 35 700
40-50 17 45 765
50-60 6 55 330
Total Frequency: 100
Total Frequency Deviation: 2800.000000
The Arithmetic Mean using formula: 28.000000
```

## 3. Program to calculate the Geometric Mean using the given formula.

The **Geometric Mean** of a set of **n** observations is the **n ^{th}** root of their product. Let’s find out the Geometric Mean using the C program.

When you execute the above program, the output will look like this as shown below:

```
X F log(x) F*log(x)
1 5 0.000000 0.000000
2 9 0.693147 6.238325
3 12 1.098612 13.183348
4 17 1.386294 23.567005
5 14 1.609438 22.532131
6 10 1.791759 17.917595
The Geometric Mean: 3.474149
```

## 4. Write a program to calculate the arithmetic mean for the frequency distribution using the formula:

Class-interval | 0-8 | 8-16 | 16-24 | 24-32 | 32-40 | 40-48 |

Frequency (f) | 8 | 7 | 16 | 24 | 15 | 7 |

Let’s find out the arithmetic mean of the given frequency distribution with the C program.

When you execute the above program, the output will look like this as shown below:

```
Class Interval Mid Value (x) Frequency (f) d=(x-A)/h fd
0- 8 4 8 -3 -24
8-16 12 7 -2 -14
16-24 20 16 -1 -16
24-32 28 24 0 0
32-40 36 15 1 15
40-48 44 7 2 14
Total Frequency: 77
Total Frequency Distribution: -25
The Arithmetic Mean using Formula: 25.402597
```

## 5. Write a program to calculate the arithmetic median of the following frequency distribution.

x | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |

f | 8 | 10 | 11 | 16 | 20 | 25 | 15 | 9 | 6 |

The **Median** of a distribution is the value of the variable which divides it into two equal parts. Let’s find out the arithmetic median of the given frequency distribution using the C program.

When you execute the above program, the output will look like this as shown below:

```
COMPUTATION OF MEDIAN
X FREQUENCY C.F.
1 8 8
2 10 18
3 11 29
4 16 45
5 20 65
6 25 90
7 15 105
8 9 114
9 6 120
Cumulative Frequency is greater than 60 is 65.
The Value of x corresponding to 65 is 5.
```

## 6. Write a program to calculate the median for continuous frequency distribution using the formula.

x | 2000-3000 | 3000-4000 | 4000-5000 | 5000-6000 | 6000-7000 |

f | 3 | 5 | 20 | 10 | 5 |

In the case of continuous frequency distribution, the class corresponding to the cumulative frequency just greater than **N/2** is called the median class. Let’s find out the value of the median by the above formula using the C program for the given frequency distribution.

When you execute the above program, the output will look as shown below.

```
COMPUTATION OF MEDIAN
Class Interval FREQUENCY C.F.
2000-3000 3 3
3000-4000 5 8
4000-5000 20 28
5000-6000 10 38
6000-7000 5 43
Cumulative Frequency is greater than 21 is 28.
The Corresponding median class is 4000-5000
The lower limit of the median class is l: 4000
The frequency of the median class is f: 20
The magnitude of the median class is h: 1000
The C.F. of the preceding the median class c: 8
The Median: 4675.000000
```

## 7. Write a program to find out the Quartile Deviation (Q.D.).

x | 0-10 | 10-20 | 20-30 | 30-40 | 40-50 | 50-60 | 60-70 |

f | 6 | 5 | 8 | 15 | 7 | 6 | 3 |

The **Quartile deviation** or **semi-interquartile range** **Q** is given by **Q = (Q3 – Q1)/2** where **Q1** and **Q3** are the first and third quartiles of the distribution respectively. Quartile deviation is a better measure than the range as it makes use of 50% of the data. But since it ignores the other 50% of the data, therefore it cannot be regarded as a reliable measure. Let’s calculate the Quartile deviation using the C program.

When you execute the above program, the output will look like this as shown below:

```
QUARTILE DEVIATION
Class Interval FREQUENCY C.F.
0-10 6 6
10-20 5 11
20-30 8 19
30-40 15 34
40-50 7 41
50-60 6 47
60-70 3 50
Q1 Class: 21.875000
Q2 Class: 45.000000
Quartile deviation: 11.562500
```

## 8. Write a program to calculate the Mean deviation (M.D.) using the formula.

x | 0-10 | 10-20 | 20-30 | 30-40 | 40-50 | 50-60 | 60-70 |

f | 6 | 5 | 8 | 15 | 7 | 6 | 3 |

If **x|f _{i}, i = 1, 2, .., n** is the frequency distribution, then the mean deviation from the average A is given by the above formula where

**|x**represents the modulus or the absolute value of the deviation

_{-i}A|**(x**, when the negative sign is ignored. Let’s find out the mean deviation by the above formula using the C program for the given frequency distribution.

_{i}-A)When you execute the above program, the output will look like this as shown below:

```
MEAN DEVIATION
Class FREQUENCY fx |x-mean(x)| f.|x-mean(x)|
0-10 6 30 28.40 170.40
10-20 5 75 18.40 92.00
20-30 8 200 8.40 67.20
30-40 15 525 1.60 24.00
40-50 7 315 11.60 81.20
50-60 6 330 21.60 129.60
60-70 3 195 31.60 94.80
Mean Deviation of Mean: 13.183999
```

## 9. You can take a trip that entails traveling 900km by train at an average speed of 60 km/h, 3000 km by boat at an average of 25 km/h, 400 km by plane at 350 km/h, and finally 15 km by taxi at 25 km/h. What is your average speed for the entire distance? Find the average speed using the Weighted Harmonic Mean formula.

Since different distances are covered with varying speeds, the required average speed for the entire distance is given by the weighted harmonic mean of the speeds (in km.p.h.), the weights being the corresponding distances covered (in km). Let’s calculate the average speed by the C program using the Harmonic Mean formula.

When you execute the above program, the output will look like this as shown below:

```
X W W/X
60 900.00 15.00
25 3000.00 120.00
350 400.00 1.14
25 15.00 0.60
Average Speed: 31.555578 km/h
```

## 10. Write a program to calculate the lower marks. If 70% of the candidates pass the paper, find the minimum marks obtained by a passing candidate.

x | 0 | 10 | 20 | 30 | 40 | 50 |

f | 500 | 460 | 400 | 200 | 100 | 30 |

Let’s solve the above problem using the C program.

When you execute the above program, the output will look like this as shown below:

```
X FREQUENCY C.F.
0 40 40
10 60 100
20 200 300
30 100 400
40 70 470
50 30 500
The Lower quartile marks: 20.
If 70% of the candidates pass in the exam, then only 30% don't pass it.
The minimum marks obtained by a pass candidate is: 20.
```

## Related:

C Programs for Practice: Learn Simple C Programs for Beginners

Simple C Programs Based on Discrete Mathematics

Vilashkumar is a Python developer with expertise in Django, Flask, API development, and API Integration. He builds web applications and works as a freelance developer. He is also an automation script/bot developer building scripts in Python, VBA, and JavaScript.