资源描述:
《c语言程序设计课后习题解答》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第3章习题解答第1章1.C语言程序主要由预处理命令、函数、注释等组成。2.填空(1)分号(2)main(3)stdio.h3.源程序:#includemain(){printf(“*************************”);printf(“HelloWorld!”);printf(“*************************”);}4.源程序:#includemain(){inta,b,c;/*定义变量*/scanf(“%d”,&a);/*输入第一个整数*/scanf(“%d”,&b);/
2、*输入第二个整数*/c=a-b;/*计算差*/printf(“%d-%d=%d”,a,b,c);/*输出结果*/}5.(1)(2)x=10;(3)printf(“s=%d”,s);第2章1.(1)c(2)a(3)bg(4)ade(5)d2.a.5b.295c.4d.29e.93.a.x=4,y=6b.x=4,y=3f.x=3,y=64.165.#includemain(){inta,b,c;scanf("%d%d",&a,&b);c=a*b;printf("%d*%d=%d",a,b,c);}第3章1.(1)b(
3、2)b(3)d(4)a(5)b2.(1)&a,&b(2)l,s3.printf(“x=%.2f,y=%.2f”,x,y);4.#includemain(){intnum1,num2,num3,sum;floataverage;scanf("%d%d%d",&num1,&num2,&num3);sum=num1+num2+num3;average=sum/3.0;printf("sum=%d,average=%.2f",sum,average);}5.#includemain(){inthour,minute,
4、second,total;/*定义变量代表时、分、秒和总秒数*/scanf("%d",&total);hour=total/3600;minute=total%3600/60;second=total%3600%60;printf("%dhours:%dminutes:%dseconds",hour,minute,second);}第4章1.(1)a(2)b(3)b(4)b(5)b2.03.(1)6(2)4(3)1(4)14.#includemain(){intx,y;scanf("%d",&x);if(x>-5&&x<0)y=5
5、*x;if(x==0)y=-1;if(x>0&&x<10)y=2*x+1;printf("x=%d,y=%d",x,y);}5.#includemain(){intscore,rank;/*score表示成绩,rank表示级别*/printf("Pleaseinputscore:");scanf("%d",&score);rank=score/10;switch(rank){case10:case9:printf("成绩等级为:A");break;case8:printf("成绩等级为:B");break;case7:pr
6、intf("成绩等级为:C");break;case6:printf("成绩等级为:D");break;default:printf("成绩等级为:E");break;}}6.#includevoidmain(){intn;printf("Pleaseinputthedigit:");scanf("%d",&n);switch(n){case1:printf("Jan");break;case2:printf("Feb");break;case3:printf("Mar");break;case4:printf
7、("Apr");break;case5:printf("May");break;case6:printf("Jun");break;case7:printf("Jul");break;case8:printf("Agu");break;case9:printf("Sep");break;case10:printf("Oct");break;case11:printf("Nov");break;case12:printf("Dec");break;}}第5章1.(1)b(2)a(3)b(4)d(5)d2.7,13.y=
8、-14.m=65.10,146.37.58.ABABCDCD9.#include