资源描述:
《最新C语言课后习题参考答案.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第2章部分习题参考答案一、单项选择题:DABDDDAAABBCD__________________________________________________第3章部分习题参考答案一、单项选择题:CACBBCDBBBADCCBDCCBB二、填空题:a!=b
2、
3、a<=cx>20&&x<30
4、
5、x<-1000非01x%3==0&&x%7==0或x%21==0__________________________________________________三、编程题2、#include#includevoidmain(){floata,b,
6、c,p,s;printf("请输入三角形的三边长:");scanf("%f%f%f",&a,&b,&c);if(a+b>c&&a+c>b&&b+c>a){p=(a+b+c)/2;s=sqrt(p*(p-a)*(p-b)*(p-c));printf("三角形面积为:%.2f",s);}elseprintf("输入的边长不能构成三角形!");}第3章习题__________________________________________________3、#includevoidmain(){intx,y;scanf("%d",&x);if(x>-5&&
7、x<0)y=x-1;elseif(x==0)y=x;elseif(x>0&&x<8)y=x+1;elsey=10;printf("y=%d",y);}if(x>-5&&x<0)y=x-1;if(x==0)y=x;if(x>0&&x<8)y=x+1;if(x<=-5
8、
9、x>=8)y=10;if(x<=-5
10、
11、x>=8)y=10;elseif(x<0)y=x-1;elseif(x==0)y=x;elsey=x+1;第3章习题__________________________________________________4、键盘输入一字符,大写转小写,小写转大写,其他原样输
12、出。#includevoidmain(){charch;scanf("%c",&ch);if(ch>='A'&&ch<='Z')ch=ch+32;elseif(ch>='a'&&ch<='z')ch=ch-32;printf("%c",ch);}ch=getchar();if(ch>='A'&&ch<='Z')printf("%c",ch+32);elseif(ch>='a'&&ch<='z')printf("%c",ch-32);elseprintf("%c",ch);第3章习题_______________________________
13、___________________8.#includevoidmain(){intyear,flag=1;doublemoney,rate,total;printf("请输入存款本金和年限:");scanf("%lf%d",&money,&year);if(year==1)rate=0.00215;elseif(year==2)rate=0.0023;elseif(year==3)rate=0.00245;elseif(year==5)rate=0.00275;elseif(year==8)rate=0.0032;elseflag=0;if(flag==
14、1){total=money*(1+rate*12*year);printf("总金额为:%.2lf",total);}elseprintf("输入的期限不正确!");}第3章习题__________________________________________________#includevoidmain(){intyear,flag=1;doublemoney,rate,total;printf("请输入存款本金和年限:");scanf("%lf%d",&money,&year);switch(year){case1:rate=0.00215
15、;break;case2:rate=0.0023;break;case3:rate=0.00245;break;case5:rate=0.00275;break;case8:rate=0.0032;break;default:printf("输入的期限不正确!");flag=0;}if(flag==1){total=money*(1+rate*12*year);printf("总金额为:%.2lf",total);}}_______________________________________