/*Mean, Median and Mode calculation*/
#include<stdio.h>
#include<math.h>
int main()
{
int i,j,n;
float a[100],t,sum=0.0,mean,median,mode;
printf("Number of data:");
scanf("%d",&n);
printf("Type the input data:\n");
for (i=0;i<n;i++)
{
scanf("%f",&a[i]);
sum=sum+a[i];
}
mean=sum/n;
printf("Mean=%f\n",mean);
/*sorting of the array*/
for (j=0;j<n;j++)
{
for(i=0;i<n;i++)
{
if (a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
if (n%2==0)
median=(a[n/2]+a[(n-2)/2])/2;
else
median=a[(n-1)/2];
mode=3*median-2*mean;
printf("Median=%f\n",median);
printf("Mode=%f\n",mode);
return(0);
}
#include<stdio.h>
#include<math.h>
int main()
{
int i,j,n;
float a[100],t,sum=0.0,mean,median,mode;
printf("Number of data:");
scanf("%d",&n);
printf("Type the input data:\n");
for (i=0;i<n;i++)
{
scanf("%f",&a[i]);
sum=sum+a[i];
}
mean=sum/n;
printf("Mean=%f\n",mean);
/*sorting of the array*/
for (j=0;j<n;j++)
{
for(i=0;i<n;i++)
{
if (a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
if (n%2==0)
median=(a[n/2]+a[(n-2)/2])/2;
else
median=a[(n-1)/2];
mode=3*median-2*mean;
printf("Median=%f\n",median);
printf("Mode=%f\n",mode);
return(0);
}
Comments
Post a Comment