#include<stdio.h>
#define MAXVAL 1000
void sort1(int a[],int n);
void median(int a[],int n);
void mode(int a[],int n);
int main()
{
int n;
int arr[MAXVAL];
int i;
printf("Enter the number of elements:");
scanf("%d",&n);
printf("Enter the values:");
for(i=0;i<n;i++)
{
printf("a[%d]=",i);
scanf("%d",&arr[i]);
}
sort1(arr,n);
median(arr,n);
mode(arr,n);
}
void sort1(int a[],int n)
{
int i;
int j;
int temp;
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
void median(int a[],int n)
{
int median;
int mid;
if((n%2)==0)
{
mid=n/2;
median=(a[mid-1]+a[mid])/2;
}
else
{
mid=(n+1)/2;
median=a[mid-1];
}
printf("The median is:%d\n",median);
}
void mode(int a[],int n)
{
int i;
int count1[MAXVAL];
for(i=0;i<n;i++)
{
count1[i]=0;
}
for(i=0;i<n;i++)
{
count1[a[i]]++;
}
i--;
int mode=count1[0];
int j;
int k;
int flag=0;
for(j=0;j<=a[i];j++)
{
if(count1[j]>count1[mode])
mode=j;
}
for(j=0;j<=a[i];j++)
{
for(k=j+1;k<=a[i];k++)
{
if(count1[j]=count1[k] && count1[j]>count1[mode])
{
flag=1;
}
}
}
if(flag==1)
{
printf("Mode cannot be calculated");
}
else
printf("the Mode is:%d",mode);
}
Chat with our AI personalities
try this---> http://c-pgms.blogspot.com/2008/08/program-to-find-meanmedianand-mode_22.html
The median of 65 and 90 is the same as their mean: 77.5The median of 65 and 90 is the same as their mean: 77.5The median of 65 and 90 is the same as their mean: 77.5The median of 65 and 90 is the same as their mean: 77.5
The mean is better than the median when there are outliers.
median is the middle number mean is average mode is most median is middle range is high - low
the median and mode are but the mean is not