全国计算机等级考试二级教程--C语言程序设计课后习题答案复习课程.doc
《全国计算机等级考试二级教程--C语言程序设计课后习题答案复习课程.doc》由会员分享,可在线阅读,更多相关《全国计算机等级考试二级教程--C语言程序设计课后习题答案复习课程.doc(62页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Good is good, but better carries it.精益求精,善益求善。全国计算机等级考试二级教程-C语言程序设计课后习题答案-全国计算机等级考试二级教程-C语言程序设计课后习题答案第一章1.1EXE1.2COBJEXE1.3顺序选择循环第二章一.选择题2.1B2.2D2.3B2.4A2.5C2.6A2.7B2.8B2.9D2.10C2.11B2.12B2.13A二.填空题2.1411122.154.24.22.16定义执行语句2.17关键字用户标识符2.18intfloatdouble2.19floata1=1;floata2=1;2.20存储单元2.213.52.22(
2、a*b)/ca*b/ca/c*b2.23把常量10赋给变量s2.24位1或02.2581270111111-128100000002.2632767-3276810000000000000002.2710816三.上机改错题2.28#includestdio.h;删除行尾的;main();/*mainfunction*/删除)后的;,注释中的*要紧靠“/”,即应为“/*”和“*/”函数开始处遗失了一个“”floatr,s;/*/*risradius*/,/*sisareaofcircuilar*/*/注释符号不可嵌套使用r=5.0;s=3.14159*r*r;printf(%fn,s)行尾遗失
3、了“;”函数结束处遗失了一个“”2.29#includestdio.hmain/*mainfunction*/main后遗失了“()”floata,b,c,v;/*a,b,caresides,visvolumeofcube*/a=2.0;b=3.0;c=4.0行尾遗失了“;”v=a*b*c;printf(%fn,v)行尾遗失了“;”第三章一.选择题3.1C3.2C3.3D3.4C3.5D3.6B3.7C3.8D3.9A3.10B3.11C3.12D3.13D3.14A3.15C3.16C3.17C3.18无答案3.19C3.20B二.填空题3.21(1)-2002500(2)i=-200,j=
4、2500(3)i=-200j=25003.2212003.23一条语句;3.24;3.25100,25.81,1.8923410025.811.8923410025.811.892343.26x=127,x=127,x=177,x=7f,x=1273.27x=127,x=127,x=$127,x=$000127,x=%06d3.28a=513.789215,a=513.79,a=513.78921500,a=513.78921500三.编程题和改错题3.29修改后的程序如下:main()doublea,b,c,s,v;printf(inputa,b,c:);scanf(%lf%lf%lf,&a
5、,&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#includemain()inta=560,b=60;printf(560minuteis%dhourand%dminute.n,a/b,a%b);3.31#includemain()inta,b;a=1500;b=350;printf(adivbis:%dn,a/b);printf(amodbis:%dn,a%b);3.32#includemain()doublea,b,c,ave;printf(input3doublenumber:
6、n);scanf(%lf%lf%lf,&a,&b,&c);printf(%.1fn,(a+b+c)/3);3.33#includevoidmain()inta,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.1A4.2A4.3A4.4D4.5C4.6A4.7B4.8C4.9D4.10C二.填空题4.11非004.12=同级=!=同级4.13
7、!&|4.15!4.16a=b|a4|x-44.1714.18x04.193224.20*#三.编程题4.21略4.22#include/*检查日期的合法性*/intcheckdate(intyear,intmonth,intday)if(year2005)printf(输入的年份无效!n);return0;elseif(month12)printf(输入的月份无效!n);return0;elseif(day31)printf(输入的日期无效!n);return0;elseswitch(month)case4:case6:case9:case11:if(day30)printf(输入的日期无效
8、!n);return0;break;case2:if(year%4=0&year%100!=0)|year%400=0)if(day29)printf(输入的日期无效!n);return0;elseif(day28)printf(输入的出生日期无效!n);return0;break;/*endofswitch(m0)*/return1;voidmain()inty0,m0,d0;/*生日*/inty1,m1,d1;/*当前日期*/intyears,months,days;/*实足年龄*/printf(请输入学生的生日:);scanf(%d%d%d,&y0,&m0,&d0);if(checkda
9、te(y0,m0,d0)printf(请输入当前日期:);scanf(%d%d%d,&y1,&m1,&d1);/*当前日期合法性检查*/if(!checkdate(y1,m1,d1)return;elseif(y0y1)printf(出生年份比当前年份晚!n);return;elseif(y0=y1)if(m0m1)printf(出生年月比当前年月晚!n);return;elseif(m0=m1)if(d0d1)printf(出生年月日比当前年月日晚!n);return;/*计算实足年龄*/years=y1-y0;months=m1-m0;days=d1-d0;/*修正实足年龄天数*/if(d
10、ays0)months-;switch(m1)case1:case5:case7:case10:case12:days+=30;break;case2:case4:case6:case8:case9:case11:days+=31;break;case3:if(y1%4=0&y1%100!=0)|y1%400=0)days+=29;elsedays+=28;break;/*endofswitch(m1)*/*endofif(days0)*/*修正实足年龄月数*/if(months0)months+=12;years-;/*endofif(monthsb)?a:b;max=(tempc)?tem
11、p:c;printf(n);printf(你输入的数中最大的是%d.n,max);4.25(1)不嵌套的if语句#includevoidmain()intx,y;printf(inputx:);scanf(%d,&x);if(x-5&x0&x=10|x=-5)printf(errorn);(2)嵌套的if语句#includevoidmain()intx,y;printf(inputx:);scanf(%d,&x);printf(n);if(x-5)printf(yis%d.n,y=x);elseprintf(error!n);if(0=x)printf(yis%d.n,y=x-1);if(x0
12、)if(x-5&x0&x10)printf(yis%d.n,y=x+1);elseprintf(error!n);(4)switch语句#includevoidmain()intx,y;printf(inputx:);scanf(%d,&x);switch(x)case-4:case-3:case-2:case-1:printf(yis%d.n,y=x);break;case0:printf(yis%d.n,y=x-1);break;case1:case2:case3:case4:case5:case6:case7:case8:case9:printf(yis%d.n,y=x+1);break
13、;default:printf(error!n);第五章一.选择题5.1D5.2C5.3B5.4C5.5C5.6B5.7D5.8A5.9D5.10D二.填空题5.115465.12死循环5.13-15.14115.15d=1.0k+k=0x三.编程题5.17#includevoidmain()inti;intsig=1;intsum=0;for(i=1;i=101;i+,i+)sum+=sig*i;sig*=-1;printf(sum=%dn,sum);5.18(1)#includevoidmain()inti;doublem=1.0;doublee=1.0;for(i=1;i=0.0004)
14、m*=i;e+=1/m;i+;printf(e=%fn,e);5.19#includevoidmain()intyear;intcol=0;for(year=1600;year=2000;year+)if(year%4=0&year%100!=0)|year%400=0)printf(%dt,year);col+;if(col%5=0)printf(n);printf(n);5.20#include#defineN7voidmain()inti;intj;intm;intk=N/2;for(i=0;im=i-k;if(m0)m*=-1;for(j=0;jprintf();for(j=0;j=0
15、&striLoop=9)num=10*num+(striLoop-0);iLoop+;printf(%dn,num);6.22#include#include#defineN80voidmain()charstrN;intnum=-1;dogets(str);num+;while(strcmp(str,EOF);printf(您输入了%d行字符!n,num);6.23#include#defineN80voidmain()charstrN;intiLoop=0;intnum=0;gets(str);while(striLoop&iLoop=a&striLoop=z)num+;iLoop+;pr
16、intf(您输入了字符中有%d个小写字母!n,num);6.24#includevoidmain()intline;intiLoop1;intiLoop2;printf(请输入图案的行数(不大于26):);scanf(%d,&line);for(iLoop1=0;iLoop1line;iLoop1+)for(iLoop2=0;iLoop2line-iLoop1;iLoop2+)printf();for(iLoop2=0;iLoop22*iLoop1+1;iLoop2+)printf(%c,iLoop1+A);printf(n);第七章一.选择题7.1C7.2C7.3B7.4C7.5A7.6D7
17、.7A二.填空题7.8127.99.0000007.1047.11n=1s7.12=yz*x7.131s*i0f(k)三.程序调试和编程题7.14fun(intn)intk,yes;for(k=2;k=n/2;k+)if(n%k=0)yes=0;break;elseyes=1;returnyes;7.15intmymod(inta,intb)returna%b;7.16doublefun(intn)doublesum=0;intiLoop;intsig=-1;for(iLoop=1;iLoop=n;iLoop+)sig*=-1;sum+=sig*1.0/iLoop;returnsum;7.17
18、doublefun(intn)doublet=1.0;intiLoop;longtmp;for(iLoop=2;iLoop=n;iLoop+)tmp=iLoop*iLoop;t-=1.0/tmp;returnt;7.18#include#includedoublefun(doublex)returnx*x+5*x+4;voidmain()intx=2;printf(y1=%fn,fun(x);printf(y2=%fn,fun(x+15);printf(y3=%fn,fun(sin(x);第八章一.选择题8.1A8.2B8.3B8.4C8.5B8.6B8.7C8.8D8.9B8.10C8.11
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 全国 计算机等级考试 二级 教程 语言程序设计 课后 习题 答案 复习 课程
限制150内