《C语言程序设计》(清华大学出版社)书后习题参考答案

2018-11-22 22:38

第一步部分 简单程序设计 P5

5.课堂实践 (1)

#include main()

{ printf(“**********\\n”); printf(“**********\\n”); printf(“**********\\n”); } (2)

#include main<> /*main()*/ {

printf(“Hello,World.\\n); } P9

5.课堂实践 (1)

#include main() {

char a=116,b=119,temp; printf(“a=%c,b=%c\\n”,a,b); temp=a; a=b; b=temp;

printf(“a=%c,b=%c\\n”,a,b); }

(2)功能:交换x,y的值; #include

main() { int x,y; x=5; y=10; x=x+y; y=x-y; x=x-y;

printf(“%d,%d”,x,y); }

(3)c:dec=120,oct=170,hex=78,ASCLL=x 4、输出内容向左靠齐 12 12

3.14159260000000000000000000000000 3.14159260000000000000000000000000 P11

5.课堂实践 (1)

①3.0-(3.0*4)/(4+2) #include main() { float x;

x=3.0-(3.0*4)/(4+2); printf(“%f”,x); }

②1/2*(2*3+2/(2*2*2)) #include main() { float x;

x=1/2*(2*3+2/(2*2*2)); printf(“%f”,x); }

(2)% (3)B (4)

#include<stdio. h> main {

x,y,z;/*没有数据类型*/ x+y=5;/*赋值表达式左边不能是表达式,应为一个变量*/

printf(\+y=,z=\,x,y,z);/*没有输入格式符*/

} P13

5.课堂实践 (1)-14

(2)(1)x=4,8 (2)8,8 (3)

#include mian() { int x=10;

printf(“当x变量的初值为%d时,进行+=运算后的结果为%d”,x,x+=x);

printf(“当x变量的初值为%d时,进行-=运算后的结果为%d”,x,x-=x);

printf(“当x变量的初值为%d时,进行*=运算后的结果为%d”,x,x*=x);

printf(“当x变量的初值为%d时,进行/=运算后的结果为%d”,x,x/=x);

} P13 习题

一、

1、C 2、C 3、A 二、 5,-4 6,12,20 P18

5.课堂实践 (1)

#include main() { int x,y;

scanf(“%d%d”,&x,&y); if(x>y)

printf(“x>y”); else if(x

printf(“x=y”); } (2)

#include main() { int x,y; scanf(“%d”,&x); if(x>0) y=1; if(x==0) y=0; if(x<0) y= -1; printf(%d”,y); } P21

5.课堂实践

(1)C (2)B (3)B (4)0.500000 scanf(\(5)不能: #include main( ) {

int x,y,z,max; if(z>y) {if(z>x) max=z; else max=x;} else if (y>x) max=y; else max=x;

printf(\=%d \} P23 略 P24 习题

一、1、D 2、D 3、C 4、D 5、B 6B 7、B

二、1、y%2==0 2、&& || ! 3、(x>2&&x<3)||(x<-10) 4、(ch>=’A’&&ch<=’z’) ch=ch-32;

5、1,0 6、F 三、 1、

#include main() {int a;

if(a%5==0&&a%7==0)

printf(\

else printf(\ }

2、

#include main() {int m;

scanf(\

if((m%4==0&&m0!=0)||m@0==0) printf(\ else printf(\} 3、

#include #include 、main() { float

a,b,c,dise,x1,x2,realpart,imagpart;

scanf(“%f%f%f”,&a,&b,&c); printf(“The equation”); if(fabs(a)<=0)

printf(“is not a quadratic\\n”); else

{ dise=b*b-4*a*c; if(dise<=0)

printf(“has two aqual roots:%8.4f\\n”,-b/(2*a));

else

if(dise>0)

{ x1=(-b+sprt(disc))/(2*a); x2=(-b-sprt(disc))/(2*a);

printf(“has distinct real roots:%8.4f (ch-key));

} (2)

and%8.4f\\n”,x1,x2);

} else {

realpart=-b/(2*a);

imagpart=sqrt(-disc)/(2*a); printf(“has complex roots:\\n”); printf(“%8.4f+%8.4f\\n”,realpart,imagpart);

printf(“%8.4f-%8.4f\\n”, realpart,imagpart);

} P28 5、课堂实践 (1)

#include main( ) { int key; char ch;

printf(\scanf(\printf(\while((ch=getchar())!='\\n') (ch-key)>122?putchar(ch+122-33-key):((ch-key)<33?putchar(ch-122-key):putchar

#include main()

{ int i; /*i没有赋值*/ int i=1;

printf(“output ten numbers:\\n”); while(i<=10)

printf(“=”);/*没有输出参数*/

{printf(“=”,i);

i++; /*应加{}组成复合语句*/ i++;}

} P30

4. 课堂实践 (1)

#include main() { int a,s=0; do

{ scanf(“%d”,&a); s+=a; }

while(a!=-1); printf(“%d”,s); } (2)

#include

main()

{ int a,b,r,t,maxB; scanf(“%d%d”,&a,&b); if(a

{ t=a;a=b;b=t;} r=a%b; while(r!=0) { a=b;b=r;r=a%b;} maxB=b;

printf(“maxB is %d”,maxB); } P33

6. 课堂实践 (1)4 (2) ①

#include main() { int i,j;

printf(\九九乘法表**\

for(i=1;i<10;i++) { for(j=1;j<=i;j++) printf(\

printf(\

} } ②

#include main()

{

int i=1,j;

while(i<10) { j=1; while(j<=i)

{ printf(\

j++;} printf(\ i++;

} } ③

#include main() {

int i=1,j; do { j=1; do

{ printf(\

j++;

}

while(j<=i); printf(\

i++;


《C语言程序设计》(清华大学出版社)书后习题参考答案.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:进出口贸易实务教材计算及案例答案:

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: