C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx

上传人:b****2 文档编号:5721796 上传时间:2023-05-05 格式:DOCX 页数:107 大小:43.08KB
下载 相关 举报
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第1页
第1页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第2页
第2页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第3页
第3页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第4页
第4页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第5页
第5页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第6页
第6页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第7页
第7页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第8页
第8页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第9页
第9页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第10页
第10页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第11页
第11页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第12页
第12页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第13页
第13页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第14页
第14页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第15页
第15页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第16页
第16页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第17页
第17页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第18页
第18页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第19页
第19页 / 共107页
C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx_第20页
第20页 / 共107页
亲,该文档总共107页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx

《C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx》由会员分享,可在线阅读,更多相关《C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx(107页珍藏版)》请在冰点文库上搜索。

C语言程序设计现代方法第二版习题答案CProgrammingAModernApproachnewWord下载.docx

,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.[was#8]Thevaluesofx,i,andywillbe12.3,45,and.6,respectively.

1.[was#4;

modified]

intmonth,day,year;

Enteradate(mm/dd/yyyy):

%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

(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);

intspeed;

Enterawindspeedinknots:

speed);

if(speed<

1)

Calm\n"

elseif(speed<

=3)

Lightair\n"

=27)

Breeze\n"

=47)

Gale\n"

=63)

Storm\n"

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))

VALID\n"

NOTVALID\n"

10.[was#14]

intgrade;

Enternumericalgrade:

grade);

if(grade<

0||grade>

100){

Illegalgrade\n"

}

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:

gotoloop_end;

loop_end:

;

/*nullstatement*/

12.[was#14]

for(d=2;

d*d<

=n;

d++)

if(n%d==0)

Theifstatementthatfollowstheloopwillneedtobemodifiedaswell:

if(d*d<

=n)

%disdivisibleby%d\n"

n,d);

else

%disprime\n"

n);

14.[was#16]Theproblemisthesemicolonattheendofthefirstline.Ifweremoveit,thestatementisnowcorrect:

if(n%2==0)

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)

%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*/

i++){

%3d"

if((start_day+i-1)%7==0)

\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.

1.[was#2]shortintvaluesareusuallystoredin16bits,causingfailureat182.intandlongintvaluesareusuallystoredin32bits,withfailureoccurringat46341.

2.[was#8]

charch;

Thisprogramprintsatableofsquares.\n"

Enternumberofentriesintable:

ch=getchar();

/*disposeofnew-l

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2