更多"以下是某C程序段,其功能为计算输入数字的阶乘。请仔细阅读程序并完成要求"的相关试题:
[多项选择]以下是某C程序段,其功能为计算输入数字的阶乘。请仔细阅读程序并完成要求。
#include<stdio.h>
#include<stdlib.h>
int main( )
int i=0;/*i为计数器*/
int n;
int 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);
getch( );
return 0;
设计一组测试用例,使该程序所有函数的语句覆盖率和分支覆盖率均能达到100%。如果认为该程序的语句或分支覆盖率无法达到100%,则说明为什么。
[简答题]
以下是某C程序段,其功能为计算输入数字的阶乘。请仔细阅读程序并完成要求。
#include<stdio.
h>
#include<stdlib. h>
int main( )
{
int i=0;/*i为计数器*/
int n;
int 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);
getch( );
return 0:
}
[简答题]以下是某C程序段,其功能为计算输入数字的阶乘。请仔细阅读程序并完成要求。
#include
#include
int main( )
int i = 0;/* i为计数器 */
int n;
int 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);
getch( );
return 0;
画出此程序主函数的控制流程图。
[简答题]以下是某C程序段,其功能是计算输入数据是否为水仙花数,请仔细阅读程序并完成要求。
#include
void main( )
int i,a,b,c;
scanf("%d ",&i);
a=i/100;
b=i/10%10;
c=i%10;
if(i==a*a*a+b*b*b+c*c*c)
printf("%d/n",i);
画出此程序主函数的控制流程图。
[简答题]
以下是某C语言程序,用来求一个数的绝对值,请仔细阅读程序并完成要求。
#include "
stdio.H"
main( )
{
float x,
y;
scanf(" %f ", &x);
if(x>0)
y=x;
else
y=-x;
printf(" %
f", y);
getch( );
}
[简答题]以下是某C语言程序,用来求一个数的绝对值,请仔细阅读程序并完成要求。
#include"stdi.h"
main( )
float x,y;
scanf("%f",&x);
if(x>0)
y=x;
else
y=-x;
printf("%f",y);
getch( );
画出此程序主函数的控制流程图。
[单项选择]若有以下程序段;
#include<iostream>
using namespace std;
int main( )
int a[]=1,4,5;
int *p=&a[0],x=6,y,z;
for(y=0;y<3;y++)
z=((*(p+y)<x) *(p+y):x);
cout<<z<<end1;
return 0;
程序运行后的输出结果是( )。
A. 1
B. 4
C. 5
D. 2
[简答题]
以下是某C程序段及其功能描述,请仔细阅读程序并完成要求
企业发放的奖金根据利润提成,发放规则如下:
利润(Ⅰ)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成。从键盘输入当月利润Ⅰ,输入应发放奖金总数。
#include
#include
int
main( )
{
long int gain;
int
prizel, prize2, prize4, prize6, prize10,prize=0;
puts("************************************");
puts("*
The program will solve *");
puts(" *
the problem of prize distribution * "):
puts("
************************************");
puts("please input the
mum of gain:");
scanf("%ld", &gain);
prizel=100000*0.1:
prize2=prizel+i00000*0.075:
prize4=prize2+200000*0.05:
prize6=prize4+200000*0.03:
prize10=prize6+400000*0.015:
if(gain<=100000)
prize=gain*0.1:
else if(gain<=200000)
prize=prizel+(gain-i00000)*0.075;
else
if(gain<=400000)
prize
[简答题]以下是某C程序段,其功能为计算输入数字的阶乘。请仔细阅读程序并完成要求。
# incllade<stdiO.h>
# incllade<stdl ib.h>
int main( )
int i:0;/*i为计数器*/
int n:
int factorial=1;/*保存阶乘的结果*/
puts("*************************************"):
puts("* The program will compute*");
puts("* the fact。tial 0f an integer*");
puts("*************************************"):
puts("please input the number n:");
scanf("%d’,&n);
if(n<0)/*判断输入的数是否大于或等于0*/
printf("please input an interget>=0./n");
return 0:
if(n==0)/*0的阶乘是1*/
printf("fa(:tOrial 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);
getch( );
return 0:
出此程序主函数的控制流程图。