C程序设计第三版课后题答案Word下载.docx
《C程序设计第三版课后题答案Word下载.docx》由会员分享,可在线阅读,更多相关《C程序设计第三版课后题答案Word下载.docx(84页珍藏版)》请在冰豆网上搜索。
(3)(75)10=(113)8=(4b)16
(4)(-617)10=(176627)8=(fd97)16
(5)(-111)10=(177621)8=(ff91)16
(6)(2483)10=(4663)8=(963)16
(7)(-28654)10=(110022)8=(9012)16
(8)(21003)10=(51013)8=(520b)16
3.6
aabb(8)cc(8)abc
(7)AN
3.7
{charc1='
C'
c2='
h'
c3='
i'
c4='
n'
c5='
a'
;
c1+=4,c2+=4,c3+=4,c4+=4,c5+=4;
%c%c%c%c%c\n"
c1,c2,c3,c4,c5);
3.8
{intc1,c2;
c1=97;
c2=98;
%c%c"
c1,c2);
3.9
(1)=2.5
(2)=3.5
3.10
9,11,9,10
3.12
(1)24
(2)10(3)60(4)0(5)0(6)0
第四章
4.4
{inta,b,c;
longintu,n;
floatx,y,z;
charc1,c2;
a=3;
b=4;
c=5;
x=1.2;
y=2.4;
z=-3.6;
u=51274;
n=128765;
c1='
c2='
b'
\n"
a=%2db=%2dc=%2d\n"
a,b,c);
x=%8.6f,y=%8.6f,z=%9.6f\n"
x,y,z);
x+y=%5.2fy+z=%5.2fz+x=%5.2f\n"
x+y,y+z,z+x);
u=%6ldn=%9ld\n"
u,n);
%c'
or%d(ASCII)\n"
c1,c1);
c2,c2);
4.5
57
57
67.856400,-789.123962
67.86-789.12,67.856400,-789.123962,67.856400,-789.123962
6.785640e+001,-7.89e+002
A,65,101,41
1234567,4553207,d687
65535,177777,ffff,-1
COMPUTER,COM
4.6
a=3b=7/
x=8.5y=71.82/
c1=Ac2=a/
4.7
1020Aa1.5-3.75+1.4,67.8/
(空3)10(空3)20Aa1.5(空1)-3.75(空1)(随意输入一个数),67.8回车
4.8
{floatpi,h,r,l,s,sq,sv,sz;
pi=3.1415926;
inputr,h\n"
%f,%f"
r,&
h);
l=2*pi*r;
s=r*r*pi;
sq=4*pi*r*r;
sv=4.0/3.0*pi*r*r*r;
sz=pi*r*r*h;
l=%6.2f\n"
l);
s=%6.2f\n"
s);
sq=%6.2f\n"
sq);
vq=%6.2f\n"
sv);
vz=%6.2f\n"
sz);
4.9
{floatc,f;
%f"
f);
c=(5.0/9.0)*(f-32);
c=%5.2f\n"
c);
4.10
#include"
stdio.h"
{charc1,c2;
%c,%c"
c1,&
c2);
putchar(c1);
putchar(c2);
%c%c\n"
第五章
5.3
(1)0
(2)1(3)1(4)0(5)1
5.4
if(a<
b)
if(b<
printf("
else
b);
elseif(a<
a);
{inta,b,c,temp,max;
temp=(a>
max=(c>
temp)?
c:
temp;
max=%d"
5.5
{intx,y;
%d"
x);
if(x<
1)y=x;
elseif(x<
10)y=2*x-1;
elsey=3*x-11;
y=%d"
y);
5.6
{intscore,temp,logic;
chargrade;
logic=1;
while(logic)
{scanf("
score);
if(score>
=0&
score<
=100)logic=0;
}
if(score==100)
temp=9;
temp=(score-score%10)/10;
switch(temp)
{case9:
grade='
A'
break;
case8:
B'
case7:
case6:
D'
case5:
case4:
case3:
case2:
case1:
case0:
E'
printf"
score=%d,grade=%c"
score,grade);
5.7
{longintnum;
intindiv,ten,hundred,thousand,ten_thousand,place;
%ld"
num);
if(num>
9999)place=5;
elseif(num>
999)place=4;
99)place=3;
9)place=2;
elseplace=1;
place=%d\n"
place);
ten_thousand=num/10000;
thousand=(num-ten_thousand*10000)/1000;
hundred=(num-ten_thousand*10000-thousand*1000)/100;
ten=(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv=num-ten_thousand*10000-thousand*1000-hundred*100-ten*10;
switch(place)
{case5:
%d,%d,%d,%d,%d\n"
ten_thousand,thousand,hundred,ten,indiv);
indiv,ten,hundred,thousand,ten_thousand);
break;
%d,%d,%d,%d\n"
thousand,hundred,ten,indiv);
indiv,ten,hundred,thousand);
%d,%d,%d\n"
hundred,ten,indiv);
indiv,ten,hundred);
%d,%d\n"
ten,indiv);
indiv,ten);
%d\n"
indiv);
5.8
{longi;
floatbonus,bon1,bon2,bon4,bon6,bon10;
bon1=100000*0.1;
bon2=bon1+100000*0.075;
bon4=bon2+200000*0.05;
bon6=bon4+200000*0.03;
bon10=bon6+400000*0.015;
i);
if(i<
=1e5)bonus=i*0.1;
elseif(i<
=2e5)bonus=bon1+(i-100000)*0.075;
=4e5)bonus=bon2+(i-200000)*0.05;
=6e5)bonus=bon4+(i-400000)*0.03;
=1e6)bonus=bon6+(i-600000)*0.015;
elsebonus=bon10+(i-1000000)*0.01;
bonus=%10.2f"
bonus);
intbranch;
branch=i/100000;
if(branch>
10)branch=10;
switch(branch)
{case0:
bonus=i*0.1;
case1:
bonus=bon1+(i-100000)*0.075;
case2:
case3:
bonus=bon2+(i-200000)*0.05;
case4:
case5:
bonus=bon4+(i-400000)*0.03;
case6:
case7
case8:
case9:
bonus=bon6+(i-600000)*0.015;
case10:
bonus=bon10+(i-1000000)*0.01;
{intt,a,b,c,d;
%d,%d,%d,%d"
c,&
d);
b){t=a;
a=b;
b=t;
c){t=a;
a=c;
c=t;
d){t=a;
a=d;
d=t;
if(b>
c){t=b;
b=c;
d){t=b;
b=d;
if(c>
d){t=c;
c=d;
%d%d%d%d\n"
a,b,c,d);
5.10
{inth=10;
floatx,y,x0=2,y0=2,d1,d2,d3,d4;
x,&
y);
d1=(x-x0)*(x-x0)+(y-y0)*(y-y0);
d2=(x-x0)*(x-x0)+(y+y0)*(y+y0);
d3=(x+x0)*(x+x0)+(y-y0)*(y-y0);
d4=(x+x0)*(x+x0)+(y+y0)*(y+y0);
if(d1>
1&
d2>
d3>
d4>
1)h=0;
h=%d"
h);
第六章循环控制
6.1
{inta,b,num1,num2,temp;
%d,%d"
num1,&
num2);
if(num1<
num2){temp=num1;
num1=num2;
num2=temp;
a=num1;
b=num2;
while(b!
=0)
{temp=a%b;
a=b;
b=temp;
num1*num2/a);
6.2
{charc;
intletters=0,space=0,digit=0,other=0;
while((c=getchar())!
='
\n'
)
{if(c>
c<
z'
||c>
Z'
)letters++;
elseif(c=='
'
)space++;
elseif(c>
0'
9'
)digit++;
elseother++;
letters=%d\nspace=%d\ndigit=%d\nother=%d\n"
letters,space,digit,other);
6.3
{inta,n,count=1,sn=0,tn=0;
n);
while(count<
=n)
{tn+=a;
sn+=tn;
a*=10;
++count;
a+aa+aaa+...=%d\n"
sn);
6.4
{floatn,s=0,t=1;
for(n=1;
n<
=20;
n++)
{t*=n;
s+=t;
s=%e\n"
6.5
{intN1=100,N2=50,N3=10;
floatk;
floats1=0,s2=0,s3=0;
for(k=1;
k<
=N1;
k++)s1+=k;
=N2;
k++)s2+=k*k;
=N3;
k++)s3+=1/k;
s=%8.2f\n"
s1+s2+s3);
6.6
{inti,j,k,n;
for(n=100;
1000;
{i=n/100;
j=n/10-i*10;
k=n%10;
if(i*100+j*10+k==i*i*i+j*j*j+k*k*k)
n=%d\n"
n);
6.7
#defineM1000
{intk0,k1,k2,k3,k4,k5,k6,k7,k8,k9;
inti,j,n,s;
for(j=2;
j<
=M;
j++)
{n=0;
s=j;
for(i=1;
i<
j;
i++)
{if((j%i)==0)
{n++;
s=s-i;
switch(n)
{case1:
k0=i;
k1=i;
k2=i;
k3=i;
k4=i;
k5=i;
k6=i;
k7=i;
case9:
k8=i;
case10:
k9=i;
if(s==0)
{printf("
j=%d\n"
j);
if(n>
1)printf("
k0,k1);
2)printf("
%d"
k2);
3)printf("
k3);
4)printf("
k4);
5)printf("
k5);
6)printf("
k6);
7)printf("
k7);
8)printf("
k8);
9)printf("
%d\n"
k9);
{staticintk[10];
=1000;
{n=-1;
k[n]=i;
for(i=0;
n;
%d,"
k[i]);
k[n]);
6.8
{intn,t,number=20;
floata=2;
b=1;
s=0;
=number;
{s=s+a/b;
t=a,a=a+b,b=t;
s=%9.6f\n"
6.9
{floatsn=100.0,hn=sn/2;
intn;
for(n=2;
=10;
{sn=sn+2*hn;
hn=hn/2;
sn=%f\n"
hn=%f\n"
hn);
6.10
{intday,x1,x2;
day=9;
x2=1;
while(day>
0)
{x1=(x2+1)*2;
x2=x1;
day--;
x1=%d\n"
x1);
6.11
math.h"
{floata,xn0,xn1;
a);
xn0=a/2;
xn1=(xn0+a/xn0)/2;
do
{xn0=xn1;
xn1=(xn0+a/xn0)/2;
while(fabs(xn0-xn1)>
=1e-5);
a=%5.2f\n,xn1=%8.2f\n"
a,xn1);
6.12
{floatx,x0,f,f1;
x=1.5;
do
{x0=x;
f=((2*x0-4)*x0+3)*x0-6;
f1=(6*x0-8)*x0+3;
x=x0-f/f1;
while(fabs(x-x0)>
x=%6.2f\n"
x);
6.13
{floatx0,x1,x2,fx0,fx1,fx2;
x1,&
x2);
fx1=x1*((2*x1-4)*x1+3)-6;
fx2=x2*((2*x2-4)*x2+3)-6;
while(fx1*fx2>
0);
{x0=(x1+x2)/2;
fx0=x0*((2*x0-4)*x0+3)-6;
if((fx0*fx1)<
{x2=x0;
fx2=fx0;
{x1=x0;
fx1=fx0;
while(fabs(fx0)>
x0=%6.2f\n"
x0);
6.14
{inti,j,k;
for(i=0;
=3;
{for(j=0;
=2-i;
"
for(k=0;
=2*i;
k++)
*"
=2;
=i;
=4-2*i;
6.15
{chari,j,k;
for(i='
x'
for(j='
{if(i!
=j)
for(k='
=k&
j!
=k)
k!
\na--%c\tb--%c\tc--%c\n"
i,j,k);
第七章数组
7.1
math.h>
#defineN101
{inti,j,line,a[N];
for(i=2;
N;
i++)a[i]=i;
sqrt(N);
for(j=i+1;
{if(a[i]!
=0&
a[j]!
if(a[j]%a[i]==0)
a[