下列程序的功能是计算数的阶乘。 main() { iht i,n; nlong np; scanf("%d",&n);
下列程序的功能是计算数的阶乘。 main() { iht i,n; nlong np; scanf("%d",&n); np=【 】; for(i=2;i<=n;i++) 【 】; printf("n=%d n!=%ld\n",n,np); }
下列程序的功能是计算数的阶乘。 main() { iht i,n; nlong np; scanf("%d",&n); np=【 】; for(i=2;i<=n;i++) 【 】; printf("n=%d n!=%ld\n",n,np); }
下列给定程序中,函数fun()的功能是:计算整数n的阶乘。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
double fun(int n)
{
double result=l.0;
whil (n>l&&n<170)
/**************found********************/
result*=--n;
/**************found********************/
return;
main()
{int. n;
clrscr();
printf("Enter an integer: ");
scanf("%d",&n);
printf("\n\n%d!=%lg\n\n ",n, fun(n));
}
注意:请勿改动main()主方法和其他已有的语句内容;仅在横线处填入适当的语句。
源程序文件代码清单如下:
public class DoWhileLoop
{
public static void main(______)
{
int n=10;
long result=1;
do
{
_____;
}
_____;
System.out.println("10的阶乘为:"+result);
}
}
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
源程序文件代码清单如下:
public class DoWhileLoop
{
public static void main(________)
{
int n=10;
long result=1;
do
{
_______________
}
______________
System.out.println("10的阶乘为: "+result);
}
}
试题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) ;
}
下列程序中,分别计算1,2,3......,10的阶乘,并输出计算结果,请将程序补充完整。
程序运行结果如下:
1!=1
2!=2
3!=6
4!=24
5!=120
6!=720
7!=5040
8!=40320
9!=362880
10!=3628800
public class ex10_1 {
public static void main(String[]args) {
long 1 Factorial;
for(int i=1;i<=10;i++) {
_____________;
for(int j=2;___________;j++)
_____________;
System.out.println(i+ " ! =" + 1Factorial);
}
}
}
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!