Simple C Programs Based on the Mathematical Statistics

Simple C Programs Based on the Mathematical Statistics

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.

arithmetic-mean-formula
x1234567
f59121714106

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.

Marks0-1010-2020-3030-4040-5050-60
No. of Students12182720176

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.

geometric-mean-formula

The Geometric Mean of a set of n observations is the nth 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:

arithmetic-mean-formula_2
Class-interval0-88-1616-2424-3232-4040-48
Frequency (f)871624157

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.

x123456789
f810111620251596

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.

median-formula
x2000-30003000-40004000-50005000-60006000-7000
f3520105

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.).

x0-1010-2020-3030-4040-5050-6060-70
f65815763

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.

mean-deviation-formula
x0-1010-2020-3030-4040-5050-6060-70
f65815763

If x|fi, i = 1, 2, .., n is the frequency distribution, then the mean deviation from the average A is given by the above formula where |x-iA| represents the modulus or the absolute value of the deviation (xi-A), 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.

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.

x01020304050
f50046040020010030

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

Scroll to Top