1、3. 在内存中,存储字符x占用1个字节,存储字符串“x”要占用_2_个字节。4. 符号常量可以用宏定义define和_ const_表示。5. 转义字符序列中的首字符是_。6. 空字符串的长度是_0_。7. 表达式coutn;还可以表示为coutendl。三、 编程题1. 编写一个程序,输入一个三位数,分别输出该数的百位、十位和个位。【参考答案】二、 选择题1 d2 a3 b4 b5 c6 a7 c三、 填空题1 下划线2 ASCII3 24 const5 6 07 coutendl;8 a+b a-b a-b9 iomanip.h iostream.h四、 编程题1#includevoid
2、main() int num,var1,var2,var3; coutnum; if(num999|num100) /用于检查输入数据的合法性 cout您的输入有误! else var1=num/100; var2=(num-var1*100)/10; var3=num%10;百位数为:var1endl 十位数为:var2个位数为:var3 第3章 C+程序的流程控制一、 选择题1 在循环语句中使用break语句的作用是( )。(a)结束本次循环 (b)结束该层循环 (c)结束所有循环 (d)结束程序执行2 对if后的括号中的表达式,要求i不为0的时候表达式为真,该表达式表示正确的为(a)i
3、(b)!i (c)i0 (d)i=03 下列循环语句的执行次数是(while(!1) cout”ok!”;(a)0次 (b)1次 (c)2次 (d) 无数次4 运行下列程序结果为( int i; for (i=0;i=10;i+) if (i%2) couti; else continue;(a)246810 (b)12345 (c)678910 (d)13579二、 填空题 结构化程序设计的三种基本结构是顺序结构、选择结构(分支结构)、循环结构。 continue语句实现的作用是_跳出本次循环。_。3若输入”china 2008!”,运行下列程序的输出结果为_。#include void m
4、ain( ) char c; int letters=0,digits=0,others=0;Please input a line charaters while (c=getchar( )!=n) if (ca & cAZ ) letters+;09 digits+; others+;letters:letters digitsdigitsothersothers double sum=0,fac=1; for(int i=1;=18;i+) _ fac*=i _ _ sum+=fac _1!+2!=setiosflags(ios:fixed)setprecision(0)sumsetpr
5、ecision(6)100|grade0) return;=70) if(grade80) degree=中 else if(grade=60)及格不及格分数:gradedegreenum2num3; if(num1num2) num=num1; num1=num2; num2=num;num3) num1=num3; num3=num; if(num2 num=num2; num2=num3;三个数按从小到大输出为:num1num2num3在100200中同时满足用3除余2,用5除余3和用7除余2的整数为: for(int i=100;=200; if(i%3=2&i%5=3&i%7=2)第4章
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1