Sunday, December 12, 2010

Find Mean ,Median And Mode of a set of Numbers

//PROGRAM TO FIND MEAN,MEDIAN AND MODE OF N GIVEN SET OF NUMBERS.
#include
#include
void main()
{
float mean,median;
int mode,sum=0,temp;
int n,i,j,pos,num[20];

int highest=0,repeat=0;
int last_num;

clrscr();
printf("\nEnter the value of n:");
scanf("%d",&n);
printf("\nEnter the %d numbers:\n",n);
for(i=0;inum[j])
{
temp=num[i];
num[i]=num[j];
num[j]=temp;
}
}
}
if(n%2==1)
{
pos=(n+1)/2;
median=num[pos];
printf("\n\nThe Median is %f",median);
}
else
{
pos=n/2;
median=(num[pos]+num[pos+1])/2;
printf("\n\nThe Median is %f",median);
}

last_num=num[0];
for(i=1;ihighest)
{
highest=repeat;
printf("%d",repeat);
mode=num[i];
}
}
else //the number was not repeated
repeat=0;
last_num=num[i];
}

printf("\n\nThe Mode is %f",mode);
getch();
}

No comments:

Post a Comment