Example: Please write the function fun, its function is to calculate: F=, F is returned as the function value. In C language, you can call log(n) function to find In(n). The reference description of log function is: double log(double x)
例如,若n的值为10,则fun函数值为3.886440。
请勿改动主函数main与其它函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
代码如下:
#include<conio.h>
#include<math.h>
#include<stdio.h>
double fun(int n)
{
int i;
double f=0.0,log(double x);
for(i=1;i<=n;i++)
f=f+log(i);
f=sqrt(f);
return f;
}
main()
{
int i;
FILE*out;
printf("%f\n",fun(10));
out=fopen("outfile.dat","w");
for(i=0;i<10;i++)
fprintf(out,"%f\n",fun(i+15));
fclose(out);
}
The output running window is as follows:
越努力越幸运!
加油,奥力给!!!