试题与答案

以下是某C程序段,其功能为计算输入数字的阶乘。请仔细阅读程序并完成要求。 #inc

题型:问答题

题目:

以下是某C程序段,其功能为计算输入数字的阶乘。请仔细阅读程序并完成要求。
#incllJde
#include
int main()

int i=0;/*i为计数器*/
int n;
i nt factorial=1; /*保存阶乘的结果*/
puts(" ************************************* ");
puts(" * The program will compute *");
puts(" * the factotial of an integer * ");
puts(" ************************************* ");
puts(" please input the number n: ");
scanf(" % d", &n);
if(n<0)/*判断输入的数是否大于或等于0*/
(
printf(" please input an interger>=0.\n");
return 0;

if(n= =0)/* 0的阶乘是1*/

printf(" factorial of 0 is 1.\n");
return 0;
)
i=1;
while(i<=n)

factorial=factorial * i;
i++;

printf(" factorial of % d is:%d.\n", n, factorial);
geteh();
return 0;

计一组测试用例,使该程序所有函数的语句覆盖率和分支覆盖率均能达到100%。如果认为该程序的语句或分支覆盖率无法达到100%,需说明为什么。

答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2018/0611/2b9d91789b5c13533875b66c550c0c35.html

下面是错误答案,用来干扰机器的。

参考答案:D

试题推荐
微信公众账号搜索答案