hey there..
this is my code...
Code:#define SIZE 100 #include<stdio.h> float mean_function(float[],int); float median_function(float[],int); float mode_function(float[],int); int main() { int i,n,choice; float array[SIZE],mean,median,mode; 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\n4.Exit"); scanf("%d",&choice); switch(choice) { case 1: mean=mean_function(array,n); printf("\n\tMean = %f\n",mean); break; case 2: median=median_function(array,n); printf("\n\tMedian = %f\n",median); break; case 3: mode=mode_function(array,n); printf("\n\tMode = %f\n",mode); break; case 4: break; default:printf("Wrong Option"); break; } }while(choice!=4); } /*************************************************************** Function Name : mean_function Purpose : to find mean Input : array of elements,no of elements Return Value : Mean Return Type : Float ****************************************************************/ float mean_function(float array[],int n) { int i; float sum=0; for(i=0;i<n;i++) sum=sum+array[i]; return (sum/n); } /*************************************************************** Function Name : median_function Purpose : to find median Input : array of elements,no of elements Return Value : Median Return Type : Float ****************************************************************/ float median_function(float a[],int n) { float temp; int i,j; for(i=0;i<n;i++) for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[j]; a[j]=a[i]; a[i]=temp; } } if(n%2==0) return (a[n/2]+a[n/2-1])/2; else return a[n/2]; } float mode_function(float a[],int n) { return (3*median_function(a,n)-2*mean_function(a,n)); }
i've got problem with "mode" formula..
the program didn't give me the correct answer..
should i use "sort()"?



LinkBack URL
About LinkBacks


