#include
#include
#include
float mean1(float[],int);
float median1(float[],int);
float mode1(float[],int);
double standarddeviation1(float[],int);
int main()
{
int i,n,choice;
float array[100],mean,median,mode;
double standarddeviation;
printf("Enter No of Elements\n");
scanf("%d",&n);
printf("Enter Elements\n");
for(i=0;i<=n;i++)
scanf("%f",&array[i]);
do
{
printf("\n\tEnter Choice\n\t1.Mean\n\t2.Median\n\t3.Mode\n\t4.Standard deviation\n\t5.Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1: mean=mean1(array,n);
printf("\n\tMean = %f\n",mean);
break;
case 2: median=median1(array,n);
printf("\n\tMedian = %f\n",median);
break;
case 3: mode=mode1(array,n);
printf("\n\tMode = %f\n",mode);
break;
case 4: standarddeviation=standarddeviation1(array,n);
printf("\n\tStandard deviation = %f\n",standarddeviation);
break;
case 5: break;
default:printf("Wrong Option");
break;
}
}while(choice!=5);
getch();
return 0;
}
float mean1(float array[],int n)
{
int i;
float sum=0;
for(i=0;i<=n;i++)
sum=sum+array[i];
return (sum/n);
}
float median1(float array[],int n)
{
float temp;
int i,j;
for(i=n-1;i=>0;i--)
{
for(j=0;j<=i;j++)
{
if(array[j]>=array[j+1])
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
if(n%2==0)
return (array[n/2]+array[n/2-1])/2;
else
return array[n/2];
}
float mode1(float array[],int n)
{
return (3*median1(array,n)-2*mean1(array,n));
}
double standarddeviation1(float array[],int n)
{
int j;
double max[100],sum,variance,mean;
mean=mean1(array,n);
sum=0;
for(j=0;j<=n;j++)
{
max[j]=pow((array[j]-mean),2);
sum+=max[j];
}
variance=sum/(j-1);
return sqrt(variance);
}
C Program to get mean ,median ,mode
Labels:
C Assignments
Subscribe to:
Post Comments (Atom)
If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE
More Useful Topics... |
|
History Of C..
In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.
My 1st Program...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}
Next Step...
#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");
printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");
}
Thanks.
ReplyDeleteWTF! mode = 3*median-2*mean ??
ReplyDeletewhile compiling this program,i got an error ....In function ‘median1’:median.c:60:19: error: expected expression before ‘>’ token.How can it be solved??plz help...
ReplyDeleteThanks in advance....