C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachWord文件下载.docx
- 文档编号:16230471
- 上传时间:2022-11-21
- 格式:DOCX
- 页数:76
- 大小:44.06KB
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachWord文件下载.docx
《C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachWord文件下载.docx》由会员分享,可在线阅读,更多相关《C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachWord文件下载.docx(76页珍藏版)》请在冰豆网上搜索。
Valueofj:
j);
Valueofk:
k);
Valueofx:
%g\n"
x);
Valueofy:
y);
Valueofz:
z);
WhencompiledusingGCCandthenexecuted,thisprogramproducedthefollowingoutput:
5618848
0
6844404
3.98979e-34
9.59105e-39
Thevaluesprinteddependonmanyfactors,sothechancethatyou'
llgetexactlythesenumbersissmall.
5.[was#10](a)isnotlegalbecause100_bottlesbeginswithadigit.
8.[was#12]Thereare14tokens:
a,=,(,3,*,q,-,p,*,p,),/,3,and;
.
AnswerstoSelectedProgrammingProjects
4.[was#8;
modified]
floatoriginal_amount,amount_with_tax;
Enteranamount:
"
);
scanf("
%f"
&
original_amount);
amount_with_tax=original_amount*1.05f;
Withtaxadded:
$%.2f\n"
amount_with_tax);
Theamount_with_taxvariableisunnecessary.Ifweremoveit,theprogramisslightlyshorter:
floatoriginal_amount;
original_amount*1.05f);
Chapter3
2.[was#2]
(a)printf("
%-8.1e"
(b)printf("
%10.6e"
(c)printf("
%-8.3f"
(d)printf("
%6.0f"
5.
respectively.
[was#8]Thevaluesofx,i,andywillbe12.3,45,and.6,
1.[was#4;
intmonth,day,year;
Enteradate(mm/dd/yyyy):
scanf("
%d/%d/%d"
month,&
day,&
year);
Youenteredthedate%d%.2d%.2d\n"
year,month,day);
3.[was#6;
intprefix,group,publisher,item,check_digit;
EnterISBN:
%d-%d-%d-%d-%d"
prefix,&
group,&
publisher,&
item,&
check_digit);
GS1prefix:
prefix);
Groupidentifier:
group);
Publishercode:
publisher);
Itemnumber:
item);
Checkdigit:
check_digit);
/*Thefiveprintfcallscanbecombinedasfollows:
%d\nGroupidentifier:
%d\nPublishercode:
%d\nItemnumber:
%d\nCheckdigit:
prefix,group,publisher,item,check_digit);
*/
}
Chapter4
2.[was#2]NotinC89.Supposethatiis9andjis7.Thevalueof(-i)/jcouldbeeither—1or—2,dependingontheimplementation.Ontheotherhand,thevalueof-(i/j)isalways—1,regardlessoftheimplementation.
InC99,ontheotherhand,thevalueof(-i)/jmustbeequaltothevalueof-(i/j).
9.[was#6]
(a)638
(b)321
(c)2-13
(d)000
13.[was#8]Theexpression++iisequivalentto(i+=1).Thevalueofbothexpressionsisiaftertheincrementhasbeenperformed.
2.[was#4]
intn;
Enterathree-digitnumber:
%d"
n);
Thereversalis:
%d%d%d\n"
n%10,(n/10)%10,n/100);
Chapter5
2.[was#2]
(a)1
(b)1
(c)1
(d)1
4.[was#4](i>
j)-(i<
j)
6.[was#12]Yes,thestatementislegal.Whennisequalto5,itdoesnothing,since5isnotequalto-9.
10.[was#16]Theoutputis
onetwo
sincetherearenobreakstatementsafterthecases.
2.[was#6]
inthours,minutes;
Entera24-hourtime:
%d:
hours,&
minutes);
Equivalent12-hourtime:
if(hours==0)
12:
%.2dAM\n"
minutes);
elseif(hours<
12)
hours,minutes);
elseif(hours==12)
%.2dPM\n"
else
hours-12,minutes);
4.[was#8;
intspeed;
Enterawindspeedinknots:
speed);
if(speed<
1)
Calm\n"
elseif(speed<
=3)
Lightair\n"
=27)printf("
Breeze\n"
=47)printf("
Gale\n"
=63)
Storm\n"
else
Hurricane\n"
6.[was#10]
intcheck_digit,d,i1,i2,i3,i4,i5,j1,j2,j3,j4,j5,first_sum,second_sum,total;
Enterthefirst(single)digit:
%1d"
d);
Enterfirstgroupoffivedigits:
%1d%1d%1d%1d%1d"
i1,&
i2,&
i3,&
i4,&
i5);
Entersecondgroupoffivedigits:
j1,&
j2,&
j3,&
j4,&
j5);
Enterthelast(single)digit:
first_sum=d+i2+i4+j1+j3+j5;
second_sum=i1+i3+i5+j2+j4;
total=3*first_sum+second_sum;
if(check_digit==9-((total-1)%10))printf("
VALID\n"
NOTVALID\n"
10.[was#14]
intgrade;
Enternumericalgrade:
grade);
if(grade<
0||grade>
100){printf("
Illegalgrade\n"
return0;
switch(grade/10){
case10:
case9:
Lettergrade:
A\n"
break;
case8:
B\n"
case7:
C\n"
case6:
D\n"
case5:
case4:
case3:
case2:
case1:
case0:
F\n"
Chapter6
4.[was#10](c)isnotequivalentto(a)and(b),becauseiisincrementedbeforetheloopbodyisexecuted.
10.[was#12]Considerthefollowingwhileloop:
while(…){
continue;
Theequivalentcodeusinggotowouldhavethefollowingappearance:
while(…){
gotoloop_end;
loop_end:
;
/*nullstatement*/
12.[was#14]
for(d=2;
d*d<
=n;
d++)if(n%d==0)
break;
Theifstatementthatfollowstheloopwillneedtobemodifiedaswell:
if(d*d<
=n)
%disdivisibleby%d\n"
n,d);
%disprime\n"
n);
14.[was#16]Theproblemisthesemicolonattheendofthefirstline.Ifweremoveit,thestatementisnowcorrect:
if(n%2==0)printf("
niseven\n"
intm,n,remainder;
Entertwointegers:
%d%d"
m,&
while(n!
=0){
remainder=m%n;
m=n;
n=remainder;
Greatestcommondivisor:
m);
4.[was#4]
floatcommission,value;
Entervalueoftrade:
value);
while(value!
=0.0f){
if(value<
2500.00f)
commission=30.00f+.017f*value;
elseif(value<
6250.00f)commission=56.00f+.0066f*value;
20000.00f)
commission=76.00f+.0034f*value;
50000.00f)commission=100.00f+.0022f*value;
500000.00f)
commission=155.00f+.0011f*value;
commission=255.00f+.0009f*value;
if(commission<
39.00f)
commission=39.00f;
Commission:
$%.2f\n\n"
commission);
6.[was#6]
inti,n;
Enterlimitonmaximumsquare:
for(i=2;
i*i<
i+=2)printf("
%d\n"
i*i);
8.[was#8]
inti,n,start_day;
Enternumberofdaysinmonth:
Enterstartingdayoftheweek(1=Sun,7=Sat):
start_day);
/*printanyleading"
blankdates"
*/
for(i=1;
i<
start_day;
i++)
/*nowprintthecalendar*/for(i=1;
i++){printf("
%3d"
if((start_day+i-1)%7==0)printf("
\n"
Chapter7
3.[was#4](b)isnotlegal.
4.[was#6](d)isillegal,sinceprintfrequiresastring,notacharacter,asitsfirstargument.
10.[was#14]unsignedint,becausethe(int)castappliesonlytoj,notj*k.
12.[was#16]Thevalueofiisconvertedtofloatandaddedtof,thentheresultisconvertedtodoubleandstoredind.
14.[was#18]No.Convertingftointwillfailifthevaluestoredinfexceedsthelargestvalueoftypeint.
AnswerstoSelectedProgrammingProjects1.[was#2]shortintvaluesareusuallystoredin16bits,causingfailureat182.intandlongintvaluesareusuallystoredin32bits,withfailureoccurringat46341.
2.[was#8]
charch;
Thisprogramprintsatableofsquares.\n"
Enternumberofentriesintable:
ch=getchar();
/*disposeofnew-linecharacterfollowingnumberofentries*//*couldsimplybegetchar();
%10d%10d\n"
i,i*i);
if(i%24==0){
PressEntertocontinue..."
/*orsimplygetchar();
5.[was#10]
ctype.h>
intsu
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言程序设计 现代 方法 第二 习题 答案 CProgrammingAModernApproach
链接地址:https://www.bdocx.com/doc/16230471.html