信息技术基础 第2版 第3章 课后习题参考答案.docx
课后习题答案1、include"stdio.h"voidmain()inta,b,c,max;printf(,pleaseinputa,b,c:");SCanf(”%d%d%d,&a,&b,&c);if(a>b)if(a>c)max=a;elsema×=c;elseif(b>c)max=b;elsema×=c;printf(,ma×=%dn"zma×);2、include"stdio.h"voidmain()intn;scanf("%d"n);if(n%2=O)printf("%d是偶数n",n);elseprintf(",%d是奇数n”,n);)3、include"stdio.h"voidmain()floatmzkgzbmim表示身高,kg表示体重Printf(”请输入身高和体重mzkg:");scanf(',%f%f"mkg);bmi=kg(m*m);if(bmi<18)printf(',bmi指数为.lf,体型偏瘦!n,zbmi);elseif(bmi<25)Primfrbmi指数为.lf,体型正常!n",bmi);elseprintf(',bmi指数为.lf,体型偏胖!n"zbmi);4、include"stdio.h"voidmain()floatx,y;Printf("请输入坐标x,y:");scanf("%f%f"×y);if(x*x+y*y>2)Printf("该坐标点在圆外!n");elseif(x*x+y*y<2)Printf("该坐标点在圆内!n");elsePrintfr该坐标点在圆上!n”);)5、#include"stdio.h"voidmain()floattotal,dtotal表示购物金额,d表示折扣Printf("请输入购物金额scanf("%f"z&total);if(total<500)d=l;elseif(total<1500)d=0.9;elseif(total<3000)d=0.8;elsed=0.7;total=total*d;Printf(',实际支出的购物金额是:.2fn,total);)6、#include"stdio.h"voidmain()intyeamonth,days;Printf(U请输入年和月:");scanf("%d%d",&year,&month);switch(month)case1:case3:case5:case 7:case 8:case10:case12:days=31;break;case4:case6:case9:casell:days=30;break;case2:if(year%400=0|year%4=0&&year%IOo!=0)闰年的判断days=29;elsedays=28;)printf("%d年%d月有d天!n",year,month,days);)7、include"stdio.h"voidmain()floata,b,cazb为两个操作数,c是计算结果charchch是运算符Printfr请输入a,ch和b:");SCanf("%f%c%f”,&a,&ch,&b);switch(ch)case'+':c=a+b;break;case'-':c=a-b;break;case'*':c=a*b;break;case,'x=ab;)Printf("%f%c%f=%.2fr,a,ch,b,c);