全国计算机等级考试二级教程--C语言程序设计课后习题答案.doc

上传人:桔**** 文档编号:513800548 上传时间:2022-11-20 格式:DOC 页数:37 大小:53.50KB
返回 下载 相关 举报
全国计算机等级考试二级教程--C语言程序设计课后习题答案.doc_第1页
第1页 / 共37页
全国计算机等级考试二级教程--C语言程序设计课后习题答案.doc_第2页
第2页 / 共37页
全国计算机等级考试二级教程--C语言程序设计课后习题答案.doc_第3页
第3页 / 共37页
全国计算机等级考试二级教程--C语言程序设计课后习题答案.doc_第4页
第4页 / 共37页
全国计算机等级考试二级教程--C语言程序设计课后习题答案.doc_第5页
第5页 / 共37页
点击查看更多>>
资源描述

《全国计算机等级考试二级教程--C语言程序设计课后习题答案.doc》由会员分享,可在线阅读,更多相关《全国计算机等级考试二级教程--C语言程序设计课后习题答案.doc(37页珍藏版)》请在金锄头文库上搜索。

1、全国计算机等级考试二级教程-C语言程序设计课后习题答案第一章 1.1 EXE 1.2 C OBJ EXE 1.3 顺序 选择 循环 第二章 一. 选择题 2.1 B 2.2 D 2.3 B 2.4 A 2.5 C 2.6 A 2.7 B 2.8 B 2.9 D 2.10 C 2.11 B 2.12 B 2.13 A 二. 填空题 2.14 11 12 2.15 4.2 4.2 2.16 定义 执行语句 2.17 关键字 用户标识符 2.18 int float double 2.19 float a1=1; float a2=1; 2.20 存储单元 2.21 3.5 2.22 (a*b)/c

2、 a*b/c a/c*b 2.23 把常量10赋给变量s 2.24 位 1或0 2.25 8 127 0111111 -128 10000000 2.26 32767 -32768 1000000000000000 2.27 10 8 16 三. 上机改错题 2.28 #include stdio.h; 删除行尾的; main(); / * main function * / 删除)后的;,注释中的*要紧靠“/”,即应为“/*”和“*/” 函数开始处遗失了一个“” float r,s ; /*/*r is radius*/,/* s is area of circuilar*/*/ 注释符号不

3、可嵌套使用 r = 5.0 ; s = 3.14159 * r * r ; printf(%fn,s) 行尾遗失了“;” 函数结束处遗失了一个“” 2.29 #include stdio.h main /* main function */ main后遗失了“()” float a,b,c,v; /*a,b,c are sides, v is volume of cube */ a=2.0; b=3.0; c=4.0 行尾遗失了“;” v=a*b*c; printf(%fn, v) 行尾遗失了“;” 第三章 一. 选择题 3.1 C 3.2 C 3.3 D 3.4 C 3.5 D 3.6 B

4、3.7 C 3.8 D 3.9 A 3.10 B 3.11 C 3.12 D 3.13 D 3.14 A 3.15 C 3.16 C 3.17 C 3.18 无答案 3.19 C 3.20 B 二. 填空题 3.21 (1)-2002500(2)i=-200,j=2500 (3)i=-200 j=2500 3.22 12 0 0 3.23 一条语句 ; 3.24 ; 3.25 100,25.81,1.89234 100 25.81 1.89234 100 25.81 1.89234 3.26 x=127,x= 127,x= 177,x= 7f,x= 127 3.27 x=127,x=127 ,

5、x=$127 ,x=$000127,x=%06d 3.28 a=513.789215,a= 513.79,a= 513.78921500,a= 513.78921500 三. 编程题和改错题 3.29 修改后的程序如下: main() double a,b,c,s,v; printf(input a,b,c:); scanf(%lf%lf%lf,&a,&b,&c); s =a*b; v=a*b*c; printf(a=%f,b=%f,c=%fn, a,b,c); printf(s=%f,v=%fn,s,v); 3.30 #include main() int a=560,b=60; print

6、f(560 minute is %d hour and %d minute.n,a/b,a%b); 3.31 #include main() int a,b; a=1500;b=350; printf(a div b is : %dn,a/b); printf(a mod b is : %dn,a%b); 3.32 #include main() double a,b,c,ave; printf (input 3 double number : n); scanf (%lf%lf%lf,&a,&b,&c); printf (%.1fn,(a+b+c)/3); 3.33 #include voi

7、d main() int a,b,c,t; printf(请依次输入整数a,b,c:); scanf(%d%d%d,&a,&b,&c); printf(n你输入的值是: a=%d,b=%d,c=%dn,a,b,c); t=b;b=a;a=c;c=t; printf(交换之后的值是:a=%d,b=%d,c=%dn,a,b,c); 第四章 一. 选择题 4.1 A 4.2 A 4.3 A 4.4 D 4.5 C 4.6 A 4.7 B 4.8 C 4.9 D 4.10 C 二. 填空题 4.11 非0 0 4.12 = =同级 = !=同级 4.13 ! & | 4.15 ! 4.16 a = b

8、 | a 4 | x -4 4.17 1 4.18 x 0 4.19 3 2 2 4.20 *# 三. 编程题 4.21 略 4.22 #include /* 检查日期的合法性 */ int checkdate(int year, int month, int day) if(year 2005) printf(输入的年份无效!n); return 0; else if(month 12) printf(输入的月份无效!n); return 0; else if(day 31) printf(输入的日期无效!n); return 0; else switch(month) case 4: ca

9、se 6: case 9: case 11: if(day 30) printf(输入的日期无效!n); return 0; break; case 2: if(year%4 = 0 & year%100 != 0) | year%400 = 0) if(day 29) printf(输入的日期无效!n); return 0; else if(day 28) printf(输入的出生日期无效!n); return 0; break; /* end of switch(m0)*/ return 1; void main() int y0, m0, d0; /* 生日 */ int y1, m1,

10、 d1; /* 当前日期 */ int years, months, days; /* 实足年龄*/ printf(请输入学生的生日:); scanf(%d%d%d, &y0,&m0,&d0); if(checkdate(y0, m0, d0) printf(请输入当前日期:); scanf(%d%d%d, &y1,&m1,&d1); /*当前日期合法性检查*/ if(!checkdate(y1, m1, d1) return; else if(y0 y1) printf(出生年份比当前年份晚!n); return; else if(y0 = y1) if(m0 m1) printf(出生年月

11、比当前年月晚!n); return; else if(m0 = m1) if(d0 d1) printf(出生年月日比当前年月日晚!n); return; /* 计算实足年龄 */ years = y1 - y0; months = m1 - m0; days = d1 - d0; /* 修正实足年龄天数*/ if(days 0) months-; switch(m1) case 1: case 5: case 7: case 10: case 12: days += 30; break; case 2: case 4: case 6: case 8: case 9: case 11: day

12、s += 31; break; case 3: if(y1%4 = 0 & y1%100 != 0) | y1%400 = 0) days += 29; else days += 28; break; /* end of switch(m1) */ /* end of if(days 0) */ /* 修正实足年龄月数*/ if(months 0) months += 12; years-; /* end of if(months b)? a:b; max=(tempc)? temp:c; printf (n); printf (你输入的数中最大的是 %d.n,max); 4.25 (1)不嵌套的if语句 #include void mai

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 机械/制造/汽车 > 电气技术

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号