当前位置:首页 > 第三章-1(3-14作业)
3月14日作业 第三章在(请于2014年3月21日批改完毕并登记成绩)
一、 选择题 (20分)
1. 若x=0,y=3,z=3,以下表达式值为0的是 A. !x B.x 2. 以下运算符中优先级最低的运算符为 ,优先级最高的为 。 A. && B. ! C. != D. || E. ?: F. == 3. 若w=1,x=2,y=3,z=4,则条件表达式w 4. 若w,x,z均为int型变量,则执行以下语句后的输出为 。 w=3;z=7;x=10; printf(\printf(\printf(\printf(\ A. 0 B. 1 C. 0 D. 0 1 1 1 1 1 1 0 0 1 1 1 0 二、读程序写结果 (15分) 1. include main() { int a=-1,b=4,k; k=(a++<=0)&&(!(b--<=0)); printf(\ } 2 . main() { int x=1,y=1,z=10; if(z<0) if(y>0) x=3; else x=5; printf(\if(z=y<0) x=3; else if(y==0) x=5; else x=7; printf(\printf(\ } 3月14日作业 第三章在(请于2014年3月21日批改完毕并登记成绩) 3 . main() { char x=‘B’; switch(x) { case ‘A’: printf(“It is A.”); case ‘B’: printf(“It is B.”); case ‘C’: printf(“It is C.”); default: printf(“other.”); } } 二、 填空题(每空2分,共40分) 1. 若a=5,b=6,c=7,d=8,则表达式d=a/2&&b==c||!a的值为 (1) 2. 定义 int x=10,y,z;执行y=z=x;x=y==z后,变量x的值为 (2) 。 3. 分段函数:输入x,计算y值,输出y,其中: x<0 y=2x+3 x=0,y=0 x>0,y=(x+7)/3 #include int x,y; scanf(\ if(x<0) (1) ; (2) y=0; (3) y=(x+7)/3; printf(“%d”,y); } 4. 由键盘输入三个数,计算以这三个数为边长的三角形面积。 (1) main() { (2) ; printf(\ scanf(\ if( (3) ) { s=(a+b+c)*0.5; s1=s*(s-a)*(s-b)*(s-c); s= (4) ; 3月14日作业 第三章在(请于2014年3月21日批改完毕并登记成绩) printf(\ } (5) printf(\ } 5. 有一方程ax+bx+c=0,a,b,c的值由键盘输入,请编程序,打印出以下情况时方程 的解。 (1) a=0,b≠0 (2) a=0,b=0,c=0 (3) a=0,b=0,c≠0 (4) a≠0,b-4ac≥0 (5) a≠0,b-4ac≤0 222 #include \main() { float a,b,c,d,pr,pi,x1,x2; scanf(\ printf(\ if(a==0) { if( (1) ) printf(\ else if( (2) )printf(\ else printf(\ } else { d=b*b-4*a*c; if( (3) ) { x1=(-b+sqrt(d))/ (4) ; x2=(-b-sqrt(d))/ (5) ; printf(\ } else { pr=-b/(2*a); (6) ; printf(\ printf(\ } 3月14日作业 第三章在(请于2014年3月21日批改完毕并登记成绩) } } 6. 投票表决器: – 输入Y、y,打印agree – 输入N、n,打印disagree – 输入其他,打印lose main() { char c; scanf(\ (1) { } 三、 编程题目:(25分,每题12.5分) 1.输入一个字符,判断它如果是小写字母输出其对应大写字母;如果是大写字母输出其对应小写字母;如果是数字输出数字本身;如果是空格,输出“space”;如果不是上述情况,输出“other”。 2.读入1到7之间的某个数,输出表示一星期中相应的某一天的单词:Monday、 Tuesday等等,用switch语句做。 case ‘Y’: case ‘y’: printf(“agree”); (2) ; case ‘N’: case ‘n’: printf(“disagree”); (3) ; (4) :printf(“lose”);
共分享92篇相关文档