功能:编写函数fun其功能是:根据整型形参m,计算如下
功能:编写函数fun其功能是:根据整型形参m,计算如下公式的值:y=1/2!+1/4!+...+1/m!(m是偶数)
#include<stdio.h>
double fun(int m)
{
_____1_____
int i,j;
double s=1;
for(_____2_____)
{
for(_____3_____)
_____4_____
_____5_____
}
_____6_____
}
void main()
{
int n;
void TestFunc();
printf("Enter n: ");
scanf("%d", &n);
printf("\nThe result is %1f\n", fun(n));
TestFunc();
}
void TestFunc()
{
FILE *IN,*OUT;
int t;
double o;
int c;
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(c=1;c<=5;c++)
{
fscanf(IN,"%d",&t);
o=fun(t);
fprintf(OUT,"%lf\n",o);
}
fclose(IN);
fclose(OUT);
}答案
第1空:double y=0.0;
第2空:i=2;i<=m;i+=2
第3空:j=i-1;j<=i;j++
第4空:s=s*j;
第5空:y=y+1.0/s;
第6空:return y;