1、C语言程序设计张淑华朱丽莉版课后习题参考答案C语言程序设计(张淑华、朱丽莉版)课后习题参考答案 C语言程序设计(张淑华、朱丽莉主编)课后习题解答(仅供参考)习 题 一一、选择题1B 2D 3B 4A 5B6C 7C二、填空题1.obj 2函数 3/* */ 4#include int a,b; a,b 三、简答题(略) 习 题 二一、选择题1B 2B 3A 4D 5A6C 7C 8A 9C 10B11A 12A 13C 14A 15C二、填空题1变量 2存储数据的单元 3非0、0 4(1)a=0 (2)051 61 7-30 838 94 , 710-6 177772 119.9 127 三、
2、写出下列程序的运行结果10,0,5 218 364 512 8 455d4,c四、编程题1#include #define PI 3.1415926 void main() float r,s; printf(“Please input circinal radiin”); scanf(“%f”,&r); s=PI*r*r; printf(“r=%.2f,s=%.2fn”,r,s); 2#include void main() char c1,c2; printf(“Please input a majusculen”); scanf(“%c”,&c1); c2=c1A&c1Z?c1+32:c
3、1; printf(“%cn”,c2); 3#include void main() int a=0,b; scanf(“%c”,&b); b=b&a; printf(“b=%dn”,b); 习 题 三一、选择题1C 2C 3A 4C 5D6原题第2行应为 c=(c-=a-5),(a=b,b+3); 答案为B 否则输出结果为5,0,57D 8C 9A 10B 二、填空题1-50 300、a=-50,b=300 a=-50 b=300210 20 30、10,20,30、a=10,b=20,c=30315、0、0三、写出下列程序的运行结果1a=789.654321,a= 789.65,a= 78
4、9.65432100,a=789.6543212b=15,b=17,b=f 3c=1,x=0,y=0,z=1 421 20,205在TC环境下为216,125 在VC环境下为 216,1806a=A,b=d,c=F 79,4,12,12 8x=4.500000,y=4,x+y=8.500000四、编程题1#include void main() printf(*n); printf( HAPPY NEW YEAR! n); printf(*n); 2 (1) #include void main() int a=5,b=8,c=10,m,max; m= ab?a:b; max=cm?c:m;
5、printf(“max=%dn”,max); (2)#include void main() int a,b,c,m,max; scanf(%d,%d,%d,&a,&b,&c); max=ab?a:(bc?b:c); printf(“max=%dn”,max); 习 题 四一、选择题1D 2D 3C 4A 5D6A 7C 8C 9D 10B二、填空题16、5、5 2(a%3=0|a%7=0) 3(1) ab (2) a=c; (3) a,b,c三、写出下列程序的运行结果14 264 3a=7,b=4 446 46 5*# 46四、编程题1另见填空题3 #include void main()
6、float a,b,c,t; scanf(%f,%f,%f,&a,&b,&c); if (ab) t=a;a=b;b=t; if (ac) t=a;a=c;c=t; if (bc) t=b;b=c;c=t; printf(“%.2f,%.2f,%.2fn”,a,b,c); 2#include void main() int a,b; scanf(%d,%d,&a,&b); if(a%b=0) printf(“%d is divisible by %dn”,a,b); else printf(“%d is not divisible by %dn”,a,b); 3(1) #include voi
7、d main() int x,y; scanf(“%d”,&x); if (x-5&x0&x10) y=x+1; printf(y=%dn,y); else printf(Data out of rangen); (2) #include void main() int x,y; scanf(“%d”,&x); switch(x) case -1: case -2: case -3: case -4:y=x; printf(y=%dn,y);break; case 0:y=x-1; printf(y=%dn,y);break; case 1: case 2: case 3: case 4: c
8、ase 5: case 6: case 7: case 8: case 9:y=x+1; printf(y=%dn,y);break; default: printf(Data out of rangen); 4#include void main() long num; int indiv,ten,hundred,thousand,tenthousand,place; /*分别代表个位、十位、百位、千位、万位和位数*/ printf(“Please Input a integer(099999):”); scanf(“%ld”,&num); if (num9999) place=5; els
9、e if (num999) place=4; else if (num99) place=3; else if (num9) place=2; else place=1; printf(“place=%dn”,place); printf(“For each digit:”); tenthousand=num/10000; thousand=(int)(num-tenthousand*10000)/1000; hundred=(int)(num-tenthousand*10000-thousand*1000)/100; ten=(int)(num-tenthousand*10000-thous
10、and*1000-hundred*100)/10; indiv=(int)(num-tenthousand*10000-thousand*1000-hundred*100-ten*10); switch(place) case 1:printf(“%d”,indiv);break; case 2:printf(“%d,%d”,ten,indiv);break; case 3:printf(“%d,%d,%d”,hundred,ten,indiv);break; case 4:printf(“%d,%d,%d,%d”,thousand,hundred,ten,indiv);break; case
11、 5:printf(“%d,%d,%d,%d,%d”,tenthousand,thousand,hundred,ten,indiv); 习 题 五一、选择题1D 2C 3D 4B 5C6B 7C 8B 9B 10B二、填空题1(1) x=0 或 !(x0) (2) xamin2(1) i10 或 i=9 (2)j%3 或 j%3!=03(1) pi (2) fabs(t) (3)4三、写出下列程序的运行结果11 2y=-1 34 4a=2,b=8 5*7645 71 8s=0 34 23四、编程题1#include void main() int i,j,k;for (i=1;i=4;i+)
12、/*输出上面4行*号*/ for (j=1;j=5-i;j+) printf(“ “); /*输出*号前面的空格*/ for (k=1;k=2*i-1;k+) printf(“*”); /*输出*号*/ printf(“n”); /*输出完一行*号后换行*/ 2 #include stdio.hvoid main() int num,n1,n2,p=1; scanf(%d,&num); while (num) n1=num/10; n2=num%10; p*=n2; num=n1; printf(num=%d,p=%dn,num,p);3 #include stdio.hvoid main() int i; float s1,s2,s3,s4,s5,sum,avg; for(i=1;i=0 4(1) 0 (2) 65(1) gets(temp
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1