Friday, October 14, 2011

Write a C program to find following parameters for given list of elements? a. Max b. Min c. Mode d. Variance e. Standard deviation

#include

#include

main()
{
printf("\t\t1.Max\n");
printf("\t\t2.Min\n");
printf("\t\t3.Mode\n");
printf("\t\t4.Variance\n");
printf("\t\t5.Standard deviation\n\n");
int c,a[20],min,max,i,j,n,s=0,k,l,tv,mode=0,count=0,mx=0;
float x,y=0,std,z=0;
printf("Select a option from the above list:-\t");
scanf("%d",&c);
switch(c)
{
case 1:
printf("\n\t=============================>a.Max(Maximum value)<==============================================\n"); printf("Enter the No of Elements You want :\t"); scanf("%d",&n); printf("Enter the Elements You want :\n"); for(i=0;imax)
max=a[i];
}
printf("Maximum value = %d \n",max);
break;
case 2:
printf("\n\t=============================>a.Min(Minimum value)<==============================================\n"); printf("Enter the num of Elements You want :\t"); scanf("%d",&n); printf("Enter the Elements You want :\n"); for(i=0;imax)
max=a[i];
}
printf("Minimum value = %d \n",min);
break;
case 3:
("\n\t=============================>c.Mode(Mode value)<==============================================\n"); printf("Enter the num of Elements You want :\t"); scanf("%d",&n); printf("Enter the Elements You want :\n"); for(i=0;ia[j+1])
{
tv=a[j];
a[j]=a[j+1];
a[j+1]=tv;
}
}
}
for(l=0;lmx)
{
mx=count;
mode=a[l];
}
}
printf("Mode = %d \n",mode);
break;
case 4:
("\n\t=============================>d.Variance<==============================================\n"); printf("Enter the num of Elements You want :\t"); scanf("%d",&n); printf("Enter the Elements You want :\n"); for(i=0;ie. Standard deviation<==============================================\n");
printf("Enter the num of Elements You want : \t");
scanf("%d",&n);
printf("Enter the Elements You want : \n");
for(i=0;i {
scanf("%d",&a[i]);
s=s+a[i];
}
k=s/n;
for(i=0;i {
y=y+pow((a[i]-k),2);
}
z=y/n;
std=sqrt(z);
printf("Standard deviation : %f\n\n",std);
break;
default :
printf("\n Choose the right option which is with in the range 1-5 only \n\n");
}
}

No comments:

Post a Comment