资源描述:
《C语言程序设计 现代方法 第二版 习题答案 C Programming_ A Modern Approach.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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;volume
2、=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",i)
3、;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.59105
4、e-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]#include5、dio.h>intmain(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,theprogramisslightlyshorter:#inclu
6、deintmain(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("%6.0f",x);
7、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