资源描述:
《C语言程序设计现代方法第二版习题集答案解析CProgrammingAModernApproach.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、......Word文档...范文范例...供学习参考Chapter2AnswerstoSelectedExercises2.[was#2](a)Theprogramcontainsonedirective(#include)andfourstatements(threecallsofprintfandonereturn).(b)Parkinson'sLaw:Workexpandssoastofillthetimeavailableforitscompletion.3.[was#4]#include
2、intmain(void){intheight=8,length=12,width=10,volume;volume=height*length*width;printf("Dimensions:%dx%dx%d",length,width,height);printf("Volume(cubicinches):%d",volume);printf("Dimensionalweight(pounds):%d",(volume+165)/166);return0;}4.[was#6]Here'sonepos
3、sibleprogram:#includeintmain(void){inti,j,k;floatx,y,z;printf("Valueofi:%d",i);printf("Valueofj:%d",j);printf("Valueofk:%d",k);printf("Valueofx:%g",x);printf("Valueofy:%g",y);.....专业资料...可分享.下载......Word文档...范文范例...供学习参考printf("Valueofz:%g"
4、,z);return0;}WhencompiledusingGCCandthenexecuted,thisprogramproducedthefollowingoutput:Valueofi:5618848Valueofj:0Valueofk:6844404Valueofx:3.98979e-34Valueofy:9.59105e-39Valueofz:9.59105e-39Thevaluesprinteddependonmanyfactors,sothechancethatyou'llgetexactlythese
5、numbersissmall.5.[was#10](a)isnotlegalbecause100_bottlesbeginswithadigit.8.[was#12]Thereare14tokens:a,=,(,3,*,q,-,p,*,p,),/,3,and;.AnswerstoSelectedProgrammingProjects4.[was#8;modified]#includeintmain(void){floatoriginal_amount,amount_with_tax;printf("
6、Enteranamount:");scanf("%f",&original_amount);amount_with_tax=original_amount*1.05f;printf("Withtaxadded:$%.2f",amount_with_tax);return0;}Theamount_with_taxvariableisunnecessary.Ifweremoveit,theprogramisslightlyshorter:#include.....专业资料...可分享.下载.....
7、.Word文档...范文范例...供学习参考intmain(void){floatoriginal_amount;printf("Enteranamount:");scanf("%f",&original_amount);printf("Withtaxadded:$%.2f",original_amount*1.05f);return0;}Chapter3AnswerstoSelectedExercises2.[was#2](a)printf("%-8.1e",x);(b)printf("%10.6e",x);(
8、c)printf("%-8.3f",x);(d)printf("%6.0f",x);5.[was#8]Thevaluesofx,i,andywillbe12.3,45,and.6,respectively.AnswerstoSelectedProgrammingProjects1.[was#4;modified]#include