资源描述:
《c语言程序设计:现代方法第二版习题答案》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、Chapter2AnswerstoSelectedExercises2.[was#2](a)Theprogramcontainsonedirective(#include)andfourstatements(threecallsofprintfandonereturn).(b)Parkinson'sLaw:Workexpandssoastofillthetimeavailableforitscompletion.3.[was#4]#includeintmain(void){intheight=8,length=12,width=10,volume;volu
2、me=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'sonepossibleprogram:#includeintmain(void){inti,j,k;floatx,y,z;printf("Valueofi:%d
3、",i);printf("Valueofj:%d",j);printf("Valueofk:%d",k);printf("Valueofx:%g",x);printf("Valueofy:%g",y);printf("Valueofz:%g",z);return0;}WhencompiledusingGCCandthenexecuted,thisprogramproducedthefollowingoutput:Valueofi:5618848Valueofj:0Valueofk:6844404Valueofx:3.98979e-34Valueofy:9
4、.59105e-39Valueofz:9.59105e-39Thevaluesprinteddependonmanyfactors,sothechancethatyou'llgetexactlythesenumbersissmall.5.[was#10](a)isnotlegalbecause100_bottlesbeginswithadigit.8.[was#12]Thereare14tokens:a,=,(,3,*,q,-,p,*,p,),/,3,and;.AnswerstoSelectedProgrammingProjects4.[was#8;modified]#in
5、cludeintmain(void){floatoriginal_amount,amount_with_tax;printf("Enteranamount:");scanf("%f",&original_amount);amount_with_tax=original_amount*1.05f;printf("Withtaxadded:$%.2f",amount_with_tax);return0;}Theamount_with_taxvariableisunnecessary.Ifweremoveit,theprogramisslightlyshor
6、ter:#includeintmain(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);(c)printf("%-8.3f",x);(d)printf
7、("%6.0f",x);5.[was#8]Thevaluesofx,i,andywillbe12.3,45,and.6,respectively.AnswerstoSelectedProgrammingProjects1.[was#4;modified]#includeintmain(void){intmonth,day,year;printf("Enteradate(mm/dd/yyyy):");scanf("%d/%d/%d",&month,&day,&year);printf("Youent