《CPrimerPlus中文版第五版的课后编程练习答案》由会员分享,可在线阅读,更多相关《CPrimerPlus中文版第五版的课后编程练习答案(88页珍藏版)》请在金锄头文库上搜索。
1、Chapter2PE2-1/*ProgrammingExercise2-1*/ncludeintmain(void)printf(nAntonBrucknernn);printf(nAntonnBrucknernn);printf(nAntonn;printf(nBrucknernn);return0;PE2-3/*ProgrammingExercise2-3*/ncludeintmain(void)intageyears;/*ageinyears*/intagedays;/*ageindays*/*largeagesmayrequirethelongtype*/ageyears=44;age
2、days=365*ageyears;printf(nAnageof%clyearsis%cldaysn,ageyears,agedays);return0;PE2-4/*ProgrammingExercise2-4ncludevoidjolly(void);voiddeny(void);intmain(void)jolly();jolly();jolly();deny();return0;voidjolly(void)printf(nForhe1sajollygoodfellow!nn);voiddeny(void)printf(nWhichnobodycandeny!nn);PE2-5/*P
3、rogrammingExercise2-5*/ncludeintmain(void)inttoes;toes=10;printf(ntoes=%dnn/toes);printf(MTwicetoes=%dnM/2*toes);printf(Mtoessquared=%dnnztoes*toes);return0;toes*/*orcreatetwomorevariables,setthemto2*toesandtoesPE2-7/*ProgrammingExercise2-7*ncludevoidone_three(void);voidtwo(void);intmain(void)printf
4、(nstartingnow:nn);one_three();printf(ndone!nn);return0;voidone_three(void)printf(,onen,);two();printf(nthreenn);voidtwo(void)printf(ntwonn);Chapter3PE3-2/*ProgrammingExercise3-2*/ncludeintmain(void)intascii;printf(nEnteranASCIIcode:n);scanf(n%dnz&ascii);printf(n%distheASCIIcodefor警c.nM,ascii,ascii);
5、return0;PE3-4/*ProgrammingExercise3-4*/ncludeintmain(void)floatnum;printf(nEnterafloating-pointvalue:n);scanf(n%fnr&num);printf(nfixed-pointnotation:%fnn,num);printf(nexponentialnotation:%enn,num);return0;PE3-6/*ProgrammingExercise3-6#includeintmain(void)floatmass_mol=3.0e-23;/*massofwatermoleculein
6、grams*/floatmass_qt=950;/*massofquartofwateringrains*/floatquarts;floatmolecules;printf(nEnterthenumberofquartsofwater:n);scanf(n%fnz&quarts);molecules=quarts*mass_qt/mass_mol;printf(n%fquartsofwatercontain%emolecules.n,quarts,molecules);return0;Chapter4PE4-1/*ProgrammingExercise4-1*/ncludeintmain(v
7、oid)charfname40;charlname40;printf(nEnteryourfirstname:n)scanf(n%snzfname);printf(nEnteryourlastname:n);scanf(n%snzlname);printf(n%sz%snn,lname,fname);return0;PE4-4/*ProgrammingExercise4-4*/ncludeintmain(void)floatheight;charname(40;printf(nEnteryourheightininches:scanf(n%fnz&height);printf(nEnteryo
8、urname:n);scanf(n%snzname);printf(n%sfyouare咎3ffeettallnnzname,height/120);return0;PE4-6/*ProgrammingExercise4-6*/#include#includeintmain(void)floatot_f=1.0/3.0;doubleot_d=1.0/30;printf(nfloatvalues:n);printfC%.4f%.12f%.16fn,/ot_f,ot_f,ot_f);printf(ndoublevalues:n);printf(n%.4f%.12f%.16fnH,ot_d,ot_d
9、,ot_d);printf(rFLT_DIG:%dnnzFLT_DIG);printf(rDBL_DIG:%dnnzDBL_DIG);return0;Chapter5PE5-1/*ProgrammingExercise5-1*/ncludeintmain(void)constintminperhour=60;intminuteszhours,mins;printf(nEnterthenumberofminutestoconvert:n);scanf(n%dn,&minutes);while(minutes0)(hours=minutes/minperhour;mins);mins=minute
10、s%minperhour;printf(n%dminutes=%dhours,%dminutesnn,minutes,hoursfprintf(HEnternextminutesvalue(0toquit):n);scanf(n%dnz&mirwtes);spPage#of88August21、1999AnswersFoiProgianuningExercisesmCPnmeiPlus,5rdEdition,byStephenPlataprintf(ByeXn1);return0;PE5-3/*ProgrammingExercise5-3*/#includeintmain(void)const
11、intdaysperweek=7;intdays/weeks,day_rem;printf(MEnterthenumberofdays:n);scanf(n%dn,&days);weeks=days/dayspervzeek;day_rem=days%daysperweek;printf(M%ddaysare%dweeksand%ddaysn,days/weeks,day_rem);return0;PE5-5/*ProgrammingExercise5-5*/#includeintmain(void)/*findssumoffirstnintegers*/intcountzsum;intn;p
12、rintf(nEntertheupperlimit:n);scanf(fl%dr,&n);count=0;sum=0;while(count+n)sum=sum+count;printf(Hsum=%dnn,sum);return0;PE5-7/*ProgrammingExercise5-7*/#includevoidshowCube(doublex);intmain(void)/*findscubeofenterednumber*/doubleval;printf(nEnterafloating-pointvalue:n);scanf(n%lfu,&val);showCube(val);re
13、turn0;voidshowCube(doublex)printf(nThecubeof%eis咎enn,x,x*x*x);Chapter6PE6-1/*pe6-l.c*/*thisimplementationassumesthecharactercodes*/*aresequentialxastheyareinASCII*/#include#defineSIZE26intmain(void)(charlcaseSIZE;int1;for(i=0;iSIZE;i+)lcasei=+i;for(i=0;iSIZE;i+)printf(/lcasei);printf(nnn);return0;PE6-3/*pe6-3.c*/*thisimplementationassumesthecharactercodes*/*aresequentialxastheyareinASCII*/ncludeintmain(void)charlet=fF;charstart;charend;for(end=let;end=fA;end)for(start=let;start=end;start)printf(n%cnfstart);printf(nnH);return0;PE6-5/*pe6-5.c*/ncludeintmain(