i don't know anything about pointers. i wrote this code couple of weeks ago.
in the mean and median functions, i have to replace the array indexing with pointers.Code:#include<stdio.h> #include<conio.h> void main() { int x[100],n,i; float mean(int,int[]); float median(int,int[]); scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&x[i]); printf("mean=%f\n",mean(n,x)); printf("median=%f\n",median(n,x)); } float mean(int m,int a[]) { int sum=0,i; for(i= 0;i<m;i++) sum+=a[i]; return((float)sum/m) ; } float median(int n,int x[]) { int i,j, temp; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) { if(x[j]<x[i]) { temp=x[i]; x[i]=x[j]; x[j]=temp; } if(n%2==0) { return((x[n/2]+x[n/2-1])/2.0); //i was told to change this line } else return x[n/2]; //changed to return *(x+ (n/2)); } }
i have no clue how this is to be done. any help will be appreciated.



LinkBack URL
About LinkBacks



