首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
若有以下程序 #include <stdio.h> main() { int s=0, n; for (n=0; n<4; n++) { switch(n) { defau
若有以下程序 #include <stdio.h> main() { int s=0, n; for (n=0; n<4; n++) { switch(n) { defau
admin
2020-07-28
13
问题
若有以下程序
#include <stdio.h>
main()
{ int s=0, n;
for (n=0; n<4; n++)
{ switch(n)
{ default: s+=4;
case 1: s+=1;
case 2: s+=2;
case 3: s+=3;
}
}
printf("%d\n", s);
}
则程序的输出结果是
选项
A、6
B、18
C、10
D、24
答案
D
解析
第一次for循环,n的值为0,所以从default后面的语句开始执行,s+=4,s+=1,s+=2,s+=3,s的值为10,在进入第二次for循环,n的值为1,所以执行s+=1,s+=2,s+=3,s的值为16,在进入第三次for循环,n的值为2,所以执行s+=2,s+=3,s的值为21,在进入第四次for循环,n的值为3,所以执行s+=3,s的值为24。
转载请注明原文地址:https://kaotiyun.com/show/nU3p777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
有以下程序main(){inti,j,x=0;for(i=0;i<2;i++){x++;for(j=0;j<=3;j++){if(j%2)continue;x++;}x++;}printf("x=%d\n",x)
使用VC++2010打开考生文件夹下prog1中的解决方案。此解决方案的项目中包含一个源程序文件prog1.c。在此程序中,编写函数fun,该函数的功能是:统计一行字符串中单词的个数,作为函数值返回。字符串在主函数中输入,规定所有单词由小写字母组成,单词之
使用VC++2010打开考生文件夹下blank1中的解决方案。此解决方案的项目中包含一个源程序文件blank1.c。在此程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值(规定所有数均为正数),作为函数值返回,并将大于平均值的数放在形参y所指数
使用VC++2010打开考生文件夹下blank1中的解决方案。此解决方案的项目中包含一个源程序文件blank1.c。在此程序中,函数fun的功能是:计算如下公式前n项的和,并作为函数值返回。例如,当形参n的值为10时,函数返回值为9.612558。请
使用VC++2010打开考生文件夹下blank1中的解决方案。此解决方案的项目中包含一个源程序文件blank1.c。在此程序中,通过定义并赋初值的方式,利用结构体变量存储了一名学生的学号、姓名和3门课的成绩。函数fun的功能是将该学生的各科成绩都乘以一个系
在关系数据库中,描述全局数据逻辑结构的是
设二叉树的前序序列为ABDEGHCFIJ,中序序列为DBGEHACIFJ。则后序序列为
以下说法中正确的是()。
程序流程图中带有箭头的线段表示的是
E-R图中用来表示实体的图形是()。
随机试题
突触传递的易疲劳性是防止中枢神经系统过度兴奋的一种保护性机制。()
龋齿标志菌为
在工程质量验收各层次中,总监理工程师可以组织或参与( )的验收。
属于准公益性项目的是()。
报关企业、进出口收发货人应对其所属的报关员的报关行为承担相应的法律责任。()
下列有关固定资产会计核算的表述中,不正确的是()。
某一次还本付息债券的票面额为1000元,票面利率10%,必要收益率为12%,期限为5年,如果按单利计息,复利贴现,其内在价值为( )元。
下列融资方式中,()不适于商业银行在遇到短期资金紧张时获得资金。
小明每天必须做家务,做一天可得3元钱,做得特别好时每天可得5元钱,有一个月(30天)他共得100元,这个月他有()天做得特别好。
有两个弹簧振子,它们的固有频率分别为2Hz和4Hz,在频率均为2Hz的驱动力作用下分别振动着,则这两个弹簧振子()。
最新回复
(
0
)