资源描述:
《C语言程序设计内容_现代方法_答案.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、AnswerstoSelectedExercisesandProgrammingProjectsThefollowinglinksleadtoanswerstoselectedexercisesandprogrammingprojectsfromthesecondeditionofCProgramming:AModernApproach.Exercisesandprojectsforwhichanswersareprovidedaremarkedwithaiconinthebook.Note:Theseexercisesandprojectswereoriginallytheeven-nu
2、mberedexercisesinthefirstedition.(Thefirsteditiondidnotdistinguishbetweenexercisesandprogrammingprojects.)Forthebenefitofreaderswhohavethefirstedition,theoriginalexercisenumberisgiveninsquarebrackets.Forexample,thenotation[was#4]indicatesthatthenumberoftheexercise(orprogrammingproject)was4inthefir
3、stedition.Ifananswerisdifferentbecauseofsecond-editionchanges,theword"modified"willappearinsidethebrackets:[was#4;modified].Pleaseemailmewithcommentsanderrorreports.Chapter2AnswerstoSelectedExercises2.[was#2](a)Theprogramcontainsonedirective(#include)andfourstatements(threecallsofprintfandoneretur
4、n).(b)Parkinson'sLaw:Workexpandssoastofillthetimeavailableforitscompletion.3.[was#4]#includeintmain(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("Dimensionalweigh
5、t(pounds):%d",(volume+165)/166);return0;}4.[was#6]Here'sonepossibleprogram:#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);printf("Valueofz:%g",z);return0;}Whenc
6、ompiledusingGCCandthenexecuted,thisprogramproducedthefollowingoutput:Valueofi:5618848Valueofj:0Valueofk:6844404Valueofx:3.98979e-34Valueofy:9.59105e-39Valueofz:9.59105e-39Thevaluesprinteddependonmanyfactors,sothechancethatyou'llgetexactlythesenumbersissmall.5.[was#10](a)isnotlegalbecause100_bottle
7、sbeginswithadigit.8.[was#12]Thereare14tokens:a,=,(,3,*,q,-,p,*,p,),/,3,and;.AnswerstoSelectedProgrammingProjects4.[was#8;modified]#includeintmain(void){floatoriginal_amount,amount_with_tax;printf("Entera