# C Program to Find Mean,Median,Mode and Range

This is the C program to find the mean,median,mode and range of an array

Mean, median, and mode are three kinds of “averages”. There are many “averages” in statistics, but these are, I think, the three most common, and are certainly the three you are most likely to encounter in your pre-statistics courses, if the topic comes up at all.

The “mean” is the “average” you’re used to, where you add up all the numbers and then divide by the number of numbers. The “median” is the “middle” value in the list of numbers. To find the median, your numbers have to be listed in numerical order, so you may have to rewrite your list first. The “mode” is the value that occurs most often. If no number is repeated, then there is no mode for the list.

The “range” is just the difference between the largest and smallest values.

Find the mean, median, mode, and range for the following list of values:

13, 18, 13, 14, 13, 16, 14, 21, 13

The mean is the usual average, so:

(13 + 18 + 13 + 14 + 13 + 16 + 14 + 21 + 13) ÷ 9 = 15

Note that the mean isn’t a value from the original list. This is a common result. You should not assume that your mean will be one of your original numbers.

The median is the middle value, so I’ll have to rewrite the list in order:

13, 13, 13, 13, 14, 14, 16, 18, 21

There are nine numbers in the list, so the middle one will be the (9 + 1) ÷ 2 = 10 ÷ 2 = 5th number:

13, 13, 13, 13, 14, 14, 16, 18, 21

So the median is 14.

The mode is the number that is repeated more often than any other, so 13 is the mode.

The largest value in the list is 21, and the smallest is 13, so the range is 21 – 13 = 8.

mean: 15

median: 14

mode: 13

range: 8

Note: The formula for the place to find the median is “( [the number of data points] + 1) ÷ 2”, but you don’t have to use this formula. You can just count in from both ends of the list until you meet in the middle, if you prefer. Either way will work.

```
#include<stdio.h>
double arr[100];
int n;
int readarr(void)
{
printf("Enter Array Elements n");
int i;
for(i=0;i<n;i++)
{
scanf("%lf",&arr[i]);
}
}
int findmean(void)
{
double sum=0,mean;
int j;
for(j=0;j<n;j++)
{
sum+=arr[j];
}
mean=sum/n;
printf("nMean=%lfn",mean);
}
int sort(void)
{
double temp;
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(arr[j]>=arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("nThe Sorted Elements are n");
for(i=0;i<n;i++)
{
printf("%lft",arr[i]);
}
}
void range(void)
{
double max;
max=arr[n-1];
double min;
min=arr[0];
double res;
res=max-min;
printf("nRange=%lfn",res);
}
void median(void)
{
double res;
double a,b;
a=arr[n/2];
b=arr[n/2-1];
if(n%2==0)
{
res=(a+b)/2;
}
else
res=arr[n/2];
printf("nThe Median is %lfn",res);
}
int mode(int n)
{
int cnt=0,i,pos;
double mode;
int m;
for(i=0;i<n;i++)
{
if(arr[i]==arr[i+1])
{
mode=arr[i];
pos=i;
cnt++;
}
}
m=n-i;
while(m!=0)
{
mode(m);
}
printf("Moden%lf",mode);
return m;
}
main()
{
printf("Enter the Number of Entriesn");
scanf("%d",&n);
readarr();
findmean();
sort();
range();
median();
mode(n);
}
```

## Recent Comments