问题详情

答题翼 > 问答 > 计算机类考试 > 正文
目录: 标题| 题干| 答案| 搜索| 相关

试题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(“ %d!=%lg ”,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 ”,fun(n ) );

}

fclose (rf) ;

fclose (wf) ;

}

参考答案
您可能感兴趣的试题