C语言程序设计张淑华朱丽莉版课后习题参考答案文档格式.docx
《C语言程序设计张淑华朱丽莉版课后习题参考答案文档格式.docx》由会员分享,可在线阅读,更多相关《C语言程序设计张淑华朱丽莉版课后习题参考答案文档格式.docx(25页珍藏版)》请在冰豆网上搜索。
voidmain()
{floatr,s;
printf(“Pleaseinputcircinalradii\n”);
scanf(“%f”,&
r);
s=PI*r*r;
printf(“r=%.2f,s=%.2f\n”,r,s);
}
2.#include<
{charc1,c2;
printf(“Pleaseinputamajuscule\n”);
scanf(“%c”,&
c1);
c2=c1>
’A’&
&
c1<
’Z’?
c1+32:
c1;
printf(“%c\n”,c2);
3.#include<
{inta=0,b;
b);
b=b&
a;
printf(“b=%d\n”,b);
习题三
1.C2.C3.A4.C5.D
6.原题第2行应为c=(c-=a-5),(a=b,b+3);
答案为B否则输出结果为5,0,5
7.D8.C9.A10.B
1.-50300、a=-50,b=300
a=-50b=300
2.102030、10,20,30、a=10,b=20,c=30
3.15、0、0
1.a=789.654321,a=789.65,a=789.65432100,a=789.654321
2.b=15,b=17,b=f3.c=1,x=0,y=0,z=14.21
20,20
5.在TC环境下为216,125在VC环境下为216,180
6.a=A,b=d,c=F7.9,4,12,128.x=4.500000,y=4,x+y=8.500000
{printf("
**********************************\n"
);
printf("
HAPPYNEWYEAR!
\n"
2.
(1)#include<
{inta=5,b=8,c=10,m,max;
m=a>
b?
a:
b;
max=c>
m?
c:
m;
printf(“max=%d\n”,max);
(2)#include<
{inta,b,c,m,max;
scanf("
%d,%d,%d"
&
a,&
b,&
c);
max=a>
(b>
c?
b:
习题四
1.D2.D3.C4.A5.D
6.A7.C8.C9.D10.B
1.6、5、52.(a%3==0||a%7==0)3.
(1)a>
b
(2)a=c;
(3)a,b,c
1.42.643.a=7,b=44.46465.*#
46
1.另见填空题3
#include<
{floata,b,c,t;
%f,%f,%f"
if(a>
b)
{t=a;
a=b;
b=t;
}
c)
{t=a;
a=c;
c=t;
if(b>
{t=b;
b=c;
printf(“%.2f,%.2f,%.2f\n”,a,b,c);
{inta,b;
%d,%d"
if(a%b==0)
printf(“%disdivisibleby%d\n”,a,b);
else
printf(“%disnotdivisibleby%d\n”,a,b);
3.
(1)#include<
{intx,y;
scanf(“%d”,&
x);
if(x>
-5&
x<
0)
y=x;
y=%d\n"
y);
elseif(x==0)
y=x-1;
elseif(x>
0&
10)
y=x+1;
Dataoutofrange\n"
(2)#include<
{intx,y;
switch(x)
{case-1:
case-2:
case-3:
case-4:
y=x;
break;
case0:
y=x-1;
case1:
case2:
case3:
case4:
case5:
case6:
case7:
case8:
case9:
y=x+1;
default:
4.#include<
{
longnum;
intindiv,ten,hundred,thousand,tenthousand,place;
/*分别代表个位、十位、百位、千位、万位和位数*/
printf(“PleaseInputainteger(0~99999):
”);
scanf(“%ld”,&
num);
if(num>
9999)
place=5;
elseif(num>
999)
place=4;
99)
place=3;
9)
place=2;
else
place=1;
printf(“place=%d\n”,place);
printf(“Foreachdigit:
tenthousand=num/10000;
thousand=(int)(num-tenthousand*10000)/1000;
hundred=(int)(num-tenthousand*10000-thousand*1000)/100;
ten=(int)(num-tenthousand*10000-thousand*1000-hundred*100)/10;
indiv=(int)(num-tenthousand*10000-thousand*1000-hundred*100-ten*10);
switch(place)
{
printf(“%d”,indiv);
printf(“%d,%d”,ten,indiv);
printf(“%d,%d,%d”,hundred,ten,indiv);
printf(“%d,%d,%d,%d”,thousand,hundred,ten,indiv);
printf(“%d,%d,%d,%d,%d”,tenthousand,thousand,hundred,ten,indiv);
习题五
1.D2.C3.D4.B5.C
6.B7.C8.B9.B10.B
1.
(1)x>
=0或!
(x<
0)
(2)x<
amin
2.
(1)i<
10或i<
=9
(2)j%3或j%3!
=0
3.
(1)pi
(2)fabs(t)(3)4
1.12.y=-13.44.a=2,b=85.*7
6.457.18.s=0
34
23
{
inti,j,k;
for(i=1;
i<
=4;
i++)/*输出上面4行*号*/
{for(j=1;
j<
=5-i;
j++)
printf(““);
/*输出*号前面的空格*/
for(k=1;
k<
=2*i-1;
k++)
printf(“*”);
/*输出*号*/
printf(“\n”);
/*输出完一行*号后换行*/
2.#include"
stdio.h"
voidmain()
{intnum,n1,n2,p=1;
%d"
while(num)
{n1=num/10;
n2=num%10;
p*=n2;
num=n1;
num=%d,p=%d\n"
num,p);
3.#include"
{inti;
floats1,s2,s3,s4,s5,sum,avg;
for(i=1;
=6;
i++)
Pleaseenterafivesubjectsscore\n"
%f,%f,%f,%f,%f"
s1,&
s2,&
s3,&
s4,&
s5);
sum=0;
sum+=s1+s2+s3+s4+s5;
avg=sum/5;
%dindividuals,theaveragescoreis%.2f\n"
i,avg);
}
习题六
1.D2.C3.D4.D5.B
6.A7.C8.D9.A
1.地址常量2.非03.3.
(1)j=9
(2)j>
=04.
(1)0
(2)6
5.
(1)gets(temp