《C程序设计》课后习题答案(4-6章.doc
《《C程序设计》课后习题答案(4-6章.doc》由会员分享,可在线阅读,更多相关《《C程序设计》课后习题答案(4-6章.doc(23页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、C程序设计课后习题答案(4-6章)第四章8、#define PI 3.#includevoid main()float h,r,l,s,sq,vq,vz;printf(please input r,h:);scanf(%f,%f,&r,&h);l=2*PI*r;s=r*r*PI;sq=4*PI*r*r;vq=4.0/3.0*PI*r*r*r;vz=PI*r*r*h;printf(l=%6.2fn,l);printf(s=%6.2fn,s);printf(sq=%6.2fn,sq);printf(vq=%6.2fn,vq);printf(vz=%6.2fn,vz);9、#includevoid
2、main()float c,f;printf(please input f:);scanf(%f,&f);c=(5.0/9.0)*(f-32);printf(c:%6.2fn,c);第五章5、#includevoid main()int x,y;printf(please input x:);scanf(%d,&x);if(x1) y=x; printf(x=%d,y=x=%dn,x,y);else if(x10) y=2*x-1; printf(x=%d,y=2*x-1=%dn,x,y); else y=3*x-11; printf(x=%d,y=3*x-11=%dn,x,y);6、#inc
3、ludevoid main()float score;char grade;printf(please input the student score:);scanf(%f,&score);while(score100)|(score0) printf(error,please input again!n); printf(please input the student score:); scanf(%f,&score); switch(int)(score/10) case 10: case 9:grade=A;break; case 8:grade=B;break; case 7:gra
4、de=C;break; case 6:grade=D;break; case 5: case 4: case 3: case 2: case 1: case 0:grade=E;printf(score is %f,grade is %cn,score,grade);7、#include#includevoid main()long int num;int indiv,ten,hundred,thousand,ten_thousand,place;printf(please input an integer(0-99999):);scanf(%ld,&num);if(num9999) plac
5、e=5;else if(num999) place=4; else if(num99) place=3; else if(num9) place=2; else place=1;printf(Total digits:%dn,place);printf(For each number:);ten_thousand=num/10000;thousand=(int)(num-ten_thousand*10000)/1000;hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;ten=(int)(num-ten_thousand*10000
6、-thousand*1000-hundred*100)/10;indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);if(ten_thousand!=0) printf(%d,%d,%d,%d,%d,ten_thousand,thousand,hundred,ten,indiv);else if(thousand!=0) printf(%d,%d,%d,%d,thousand,hundred,ten,indiv); else if(hundred!=0) printf(%d,%d,%d,hundred,ten,
7、indiv); else if(ten!=0) printf(%d,%d,ten,indiv); else printf(%d,indiv);printf(nThe reverse number:);switch(place)case 5:printf(%d%d%d%d%d,indiv,ten,hundred,thousand,ten_thousand);break; case 4:printf(%d%d%d%d,indiv,ten,hundred,thousand);break; case 3:printf(%d%d%d,indiv,ten,hundred);break; case 2:pr
8、intf(%d%d,indiv,ten);break; case 1:printf(%d,indiv);break;8、(1)#includevoid main()long i;float bonus,bon1,bon2,bon3,bon4,bon6,bon10;bon1=*0.1;bon2=bon1+*0.075;bon4=bon2+*0.05;bon6=bon4+*0.03;bon10=bon6+*0.015;printf(please input bonus:);scanf(%ld,&i);if(i=) bonus=i*0.1;else if(i=) bonus=bon1+(i-)*0.
9、075; else if(i=) bonus=bon2+(i-)*0.05; else if(i=) bonus=bon4+(i-)*0.03; else if(i=) bonus=bon6+(i-)*0.015; else bonus=bon10+(i-)*0.01;printf(bonus:%10.2fn,bonus);(2)#includevoid main()long i;float bonus,bon1,bon2,bon4,bon6,bon10;int branch;bon1=*0.1;bon2=bon1+*0.075;bon4=bon2+*0.05;bon6=bon4+*0.03;
10、bon10=bon6+*0.015;printf(please input bonus:);scanf(%ld,&i);branch=i/;if(branch10) branch=10;switch(branch)case 0:bonus=i*0.1; break;case 1:bonus=bon1+(i-)*0.075; break;case 2:case 3:bonus=bon2+(i-)*0.05; break;case 4:case 5:bonus=bon4+(i-)*0.03; break;case 6:case 7:case 8:case 9:bonus=bon6+(i-)*0.0
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C程序设计 程序设计 课后 习题 答案
限制150内