您好,欢迎访问三一刀客
当前位置:首页 > 临时分类 > C程序设计教程(朱小菲)习题参考答案
习题1参考答案1.选择题解:1.A2.C3.D4.C5.B6.B7.C8.C9.C10.C2.填空题解:1.BCPL2.main函数3..c,.obj,.exe4..exe5.F66.Alt+X3.简答题解:略习题2参考答案一、填空题1.x20&&x30||x-1002.a%3==0&&a%5!=03.164.3215.36.07.D二、请将下面各数用八进制数和十六进制数表示解:1.15(10)=17(8)=f(16)2.32(10)=40(8)=20(16)3.80(10)=120(8)=50(16)三、选择题1.D2.B3.C4.D5.D6.A7.B8.D9.A10.C四、判断题解:1.错2.错3.错4.错5.错习题3参考答案一、填空题1.ABCD2.823.回车换行符4.Let’sgo二、写出以下程序的运行结果1.解:程序的运行结果如下:AABBCCABCAN在TurboC中的运行效果如图3-1所示。图3-1运行效果图2.解:6,3,6,23.解main(){inta,b,c;longintu,n;floatx,y,z;charc1,c2;a=7;b=8;c=9;x=3.5;y=11.1;z=-13.3;u=12354;n=130300;c1='C';c2='B';printf(\n);printf(a=%db=%dc=%d\n,a,b,c);printf(x=%8.6f,y=%8.6f,z=%9.6f\n,x,y,z);printf(x+y=%-5.2fy+z=%-5.2fz+x=%-5.2f\n,x+y,y+z,z+x);printf(u=%-6ldn=%-9ld\n,u,n);printf(c1-2='%c'\n,c1-2);printf(c2+2='%c',c2+2);}三、程序编辑题1.解,参考程序如下:main(){floatpi,h,r,l,s,sq,vq,vz;pi=3.1415926;printf(pleaseinputrandh:\n);/*请输入圆半径r圆柱高h*/scanf(%f,%f,&r,&h);l=2*pi*r;/*求圆周长l*/s=r*r*pi;/*求圆面积s*/sq=4*pi*r*r;/*求圆球表面积sq*/vq=4.0/3.0*pi*r*r*r;/*求圆球体积vq*/vz=pi*r*r*h;/*求圆柱体体积vz*/printf(l=%6.3f\n,l);printf(s=%6.3f\n,s);printf(sq=%6.3f\n,sq);printf(vq=%6.3f\n,vq);printf(vz=%6.3f,vz);}运行结果如图3-2所示:图3-2运行效果图2.解,参考程序如下:main(){floatc,f;printf(请输入一个华氏温度:\n);scanf(%f,&f);c=(5.0/9.0)*(f-32);printf(摄氏温度为:%5.2f\n,c);}习题4参考答案一、填空题1.TRUEFALSE2.****3.3二、选择题1.D2.C3.A4.A5.B三、程序编辑题1.解:参考答案如下。方法1:main(){inta,b,c;printf(请输入三个数:);scanf(%d,%d,%d,&a,&b,&c);if(ab)if(bc)printf(max=%d\n,c);elseprintf(max=%d\n,b);elseif(ac)printf(max=%d\n,c);elseprintf(max-%d\n,a);}方法2:使用条件表达式、main(){inta,b,c,temp,max;printf(请输入A,B,C:);scanf(%d,%d,%d,&a,&b,&c);printf(A=%d,B=%d,C=%d\n,a,b,c);temp=(ab)?a:b;max=(tempc)?temp:c;printf(A,B,C中最大数是%d,,max);}2.解:参考程序如下:main(){longintnum;intindiv,ten,hundred,thousand,tenthousand,place;printf(请输入一个整数(0-99999):);scanf(%ld,&num);if(num9999)place=5;elseif(num999)place=4;elseif(num99)place=3;elseif(num9)place=2;elseplace=1;printf(place=%d\n,place);printf(每位数字为:);tenthousand=num/10000;thousand=(int)(num-tenthousand*10000)/1000;hundred=(int)(num-tenthousand*10000-thousand*1000)/100;ten=(int)(num-tenthousand*10000-thousand*1000-hundred*100)/10;indiv=(int)(num-tenthousand*10000-thousand*1000-hundred*100-ten*10);switch(place){case5:printf(%d,%d,%d,%d,%d,tenthousand,thousand,hundred,ten,indiv);printf(\n反序数字为:);printf(%d%d%d%d%d\n,indiv,ten,hundred,thousand,tenthousand);break;case4:printf(%d,%d,%d,%d,thousand,hundred,ten,indiv);printf(\n反序数字为:);printf(%d%d%d%d\n,indiv,ten,hundred,thousand);break;case3:printf(%d,%d,%d\n,hundred,ten,indiv);printf(\n反序数字为:);printf(%d%d%d\n,indiv,ten,hundred);case2:printf(%d,%d\n,ten,indiv);printf(\n反序数字为:);printf(%d%d\n,indiv,ten);case1:printf(%d\n,indiv);printf(\n反序数字为:);printf(%d\n,indiv);}}运行结果:请输入一个整数(0-99999):93216↙place=5每位数字为:9,3,2,1,6反序数字为:612393.解:参考程序如下:main(){intt,a,b,c,d;printf(请输入四个数:);scanf(%d,%d,%d,%d,&a,&b,&c,&d);printf(\na=%d,b=%d,c=%d,d=%d\n,a,b,c,d);if(ab){t=a;a=b;b=t;}if(ac){t=a;a=c;c=t;}if(ad){t=a;a=d;d=t;}if(bc){t=b;b=c;c=t;}if(bd){t=b;b=d;d=t;}if(cd){t=c;c=d;d=t;}printf(\n排序结果如下:\n);printf(%d%d%d%d\n,a,b,c,d);}运行结果:请输入四个数:20,10,55,41↙a=20,b=10,c=55,d=41排序结果如下:102041554.解,参考程序如下:#includestdio.h#includeconio.hmain(){intday,month,year,sum,leap;printf(\npleaseinputyear,month,day\n);scanf(%d,%d,%d,&year,&month,&day);switch(month)/*先计算某月以前月份的总天数*/{case1:sum=0;break;case2:sum=31;break;case3:sum=59;break;case4:sum=90;break;case5:sum=120;break;case6:sum=151;break;case7:sum=181;break;case8:sum=212;break;case9:sum=243;break;case10:sum=273;break;case11:sum=304;break;case12:sum=334;break;default:printf(dataerror);break;}sum=sum+day;/*再加上某天的天数*/if(year%400||(year%4&&year%100!=0))/*判断是不是闰年*/leap=1;elseleap=0;if(leap==1&&month2)/*如果是闰年且月份大于2,总天数应该加一天*/sum++;printf(Itisthe%dthday.,sum);}运行结果:Pleaseinputyear,month,day2009,7,19↙Itisthe201thday.Pleaseinputyear,moth,day2009,2,2↙Itisthe33thday.5.解,参考程序如下:#includestdio.hmain(){charc;intletters=0,space=0,digit=0,others=0;printf(pleaseinputsomecharacters\n);while((c=getchar())!='\n'){if(c='a'&&c='z'||c='A'&&c='Z')letters++;elseif(c=='')space++;elseif(c='0'&&c='9')digit++;elseothers++;}printf(allinall:char=%dspace=%ddigit=%dothers=%d\n,letters,space,digit,others);}运行结果:pleaseinputsomecharacters520china!**Ilovechina!**allinall:char=15space=4digit=3others=6习题5参考答案一、简答题1.解循环开始时先执行初始条件,然后判断循环条件是否成立,如果成立,则执行循环体,进行步长的增加;再次判定循环条件,…;如此在循环条件、循环体和步长之间进行循环,一旦循环条件不成立,退出循环,循环结束。2.解Break语句是结束本层全部循环过程,进行外层循环或其它后续语句的执行;continue语句是结束本层的本次循环(不再执行本层循环体内continue语句的后续语句),进行下一次循环。3.解两者的重要区别在于:执行循环体时,对作为循环条件的表达式求值和验证的时间不同。while语句对作为循环条件的表达式求值和验证在执行循环体之前,而do-While语句对作为循环条件的表达式求值和验证在执行循环体之后。对于do-while语句,它的循环体至少被执行一次。二、选择题1.A2.A3.C4.A5.C6.B7.A8.B9.A10.A三、填空题1.imm%i==02.i++t=-t3.x1=0x2=x2/2-24.k=100-i*5-j*2k=0四、分析程序写出运行结果1.02.5,53.10五、编程题1.解:参考程序如下:#includemath.hmain(){floatx,sum=0,t;inti,n,p=1;scanf(%f,&x);for(n=1;n=20;n=n+2){t=1;for(i=1;i=n;i++)t=t*i;sum+=pow(x,n)/t*p;p=-p;}printf(sinxis:%.1f\n,sum);}2.解:参考程序如下:main(){longx,t,sum=0;scanf(%ld,&x);while(x!=0){t=x%10;sum+=t*t;x=x/10;}printf(%ld\n,sum);}3.解:参考程序如下:main(){intx,y,z,m,n;for(x=1;
本文标题:C程序设计教程(朱小菲)习题参考答案
链接地址:https://www.111doc.com/doc-2907591 .html