试题2本程序中,函数fun的功能是计算整数n的阶乘。程序中存在若干错误,请找出并改正。(注意:不改动
试题2
本程序中,函数fun的功能是计算整数n的阶乘。程序中存在若干错误,请找出并改正。(注意:不改动程序的结构,不得增行或删行。)
#include <stdio.h>
double fun(int n)
{ double result=1.0;
while (n>1 && n<170)
result*=- -n;
return;
}
main()
{ int n;
clrscr ();
printf(“Enter an integer:”) ;
scanf(“%d”,&n);
printf(“\n\n%d!=%lg\n\n”,n,fun(n)) ;
nono ();
{int n,i;
FILE *rf, *wf ;
rf = fopen (“g03.in”,“r”) ;
wf = fopen(“g03.out”,“w”) ;
for (i=1; i<=10;i++)
{ fscanf(rf, “%d”,&n) ;
fprintf (wf, “%lg\n”,fun(n ) );
}
fclose (rf) ;
fclose (wf) ;
}