功能:编写函数fun其功能是:根据整型形参m,计算如下公式的值:y=1+1/3+1/5+1/7+…+1/(2m+1)
例如:若m=9,则应输出:2.133256
#include <stdio.h>
void wwjt();
double fun(int m)
{
/**********Program**********/
/********** End **********/
}
main()
{
int n;
printf("Enter n: ");
scanf("%d", &n);
printf("\nThe result is %1f\n", fun(n));
wwjt();
}
void wwjt()
{
FILE *IN,*OUT;
int s,i ;
int t;
float o;
IN=fopen("in.dat","r");
if(IN==NULL)
{
printf("Read FILE Error");
}
OUT=fopen("out.dat","w");
if(OUT==NULL)
{
printf("Write FILE Error");
}
for(i=0;i<5;i++)
{
fscanf(IN,"%d",&t);
o=fun(t);
fprintf(OUT,"%f\n",o);
}
fclose(IN);
fclose(OUT);
}
登录后提交答案