#include <stdlib.h>
#include <stdio.h>
#define N 10
double fun(double x[],double *av)
{ int i,j; double d,s;
s=0;
for(i=0; i<N; i++) s = s +x[i];
*av=s/N;
d=32767;
for(i=0; i<N; i++)
if(x[i]<*av && *av - x[i]<=d){
d=*av-x[i];
j=i;
}
return x[j];
}
void main()
{ int i; double x[N],av,m;
for(i=0; i<N; i++){ x[i]=rand()%50; printf("%4.0f ",x[i]);}
printf("\n");
m=fun(x,&av);
printf("\nThe average is: %f\n",av);
printf("m=%5.1f ",m);
printf("\n");
}
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
float fun(int n)
{ float A=1;int i;
for(i=2;i<=n;i++)
A=1.0/(1+A);
return A;
}
void main()
{ int n;
system("CLS");
printf("\nPlease enter n: ");
scanf("%d",&n);
printf("A%d=%lf\n",n,fun(n));
}
|