二级C语言课后练习题答案.pdf
《二级C语言课后练习题答案.pdf》由会员分享,可在线阅读,更多相关《二级C语言课后练习题答案.pdf(70页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、课后题答案:参考答案第一章【1-1.exe 1-2.c.obj.exe 1-3 顺序,分 枝(选择),循环第二章2-1 B 2-2 D 2-3 B 2-4 A 2-5 C 2-6 A 2-7 B 2-8 B2-9 A 2-10 C 2-11 B 2-12 B 2-13 A2-14 11,12 2-15 4.2,4.2【226 ,定义说明,执行语句2-1 7 关键字,用户标识符2-18 int,float,double2-19 float a=b=l;2-2 0 存贮单元2-21 3.52-22 a*b/c,a/c*b,b/c*a 2-2 3 把 10 赋予变量 s 2-24 bit,0/12-
2、25 8,127,01111111,-128,10000000(补码)2-26 32767,-32768,1111111111111111,1000000000000000 2-27 8,10,16【2-28-1(错误)#include stdio.h;main()/*main function*/float r,s;/*/*r is radius*/,/*s is area of circular*/*/=5.0;s=3.14159*r*r;printf(%fn,s)【2-28-2(正确)#include stdio.h;main()/*main function*/float r,s;/*
3、r is radius,s is area of circular*/r=5.0;s=3.14159*r*r;printf(n%fn,s);)12-29-1(错误)#include stdio.hmain/*main function*/float a,b,c,v;/*a,b,c are sides,v is volume of cube*/a=2.0;b=3.0;c=4.0v=a*b*c;printf(M%fn,v)【2-29-2(正确)#include main()/*main function*/float a,b,c,v;/*a,b,c are sides,v is volume of
4、 cube*/a=2.0;b=3.0;c=4.0;v=a*b*c;printf(M%fn,v);第三章3-1 C 3-2 C 3-3 D 3-4 C 3-5 D 3-6 B 3-7 C3-8 D 3-9 A 3-10 B 3-11 C 3-12 D 3-13 D3-14 C 3-15 C 3-16 C 3-17 C 3-18 A 3-19 C3-20 B 3-21(l)-200 2500(2)i=-200,j=2500(3)i=-200(换行)j=25003-22 12,0,0 3-2 3 一条语句,;【3-24】;3-25 100 25.81 1.89234,100/25.81/1.8923
5、4,100/25.81 1.892343-26 x=127,x=127,x=177,x=7f,x=1273-27 x=127,x=127,x=$127,x=$000127,x=%06d3-28 a=513.789215,a=513.79,a=513.78921500,a=513.78921500【3-29-11(错误)main(double a,b,c,s,v;printf(input a,b,c:n);scanf(%d%d%d,a,b,c);s=a*b;v=a*b*c;printf(%d%d%d,a,b,c);printf(s=%fn,s,v=%dn,v);)【3-29-2(正确)main(
6、)float a,b,c,s,v;printfCinput a,b,c:”);scanf(%f%f%f:”,&a,&b,&c);s=a*b;v=a*b*c;printf(,a=%f,b=%f,c=%fn,a,b,c);printf(ns=%f,v=%fn,s,v);)3-30)main()int h,m;h=560/60;m=560%60;printf(%dh:%dm”,h,m);getch();)3-31main()int m,n;printf(input m&n:);scanf(%d%d,&m,&n);printf(,n%d,%dn,m/n,m%n);getch();)3-32main()
7、double x,y,z,s;printf(input x,y,z:);scanf(%lf%lf%lfu,&x,&y,&z);s=(x+y+z)/3.0;printf(HnAverage=%6.1 lfn,s);getch();3-33main()int a,b,c,t;printf(Input a,b,c:);scanf(%d%d%dH,&a,&b,&c);t=c;c=b;b=a;a=t;printf(,na,b,c=%d,%d,%dn,a,b,c);getch();)第四章4-1 A 4-2 A 4-3 A 4-4 D 4-5 C 4-6 A 4-7 B 4-8 A4-9 D 4-101
8、A 4-1 1 非零,零4-12,=,!=4-13!,&,ll 4-14!,关系运算符,&,ll 4-15!4-16(A)a=blla4 4-17 1 4-18 xmO)ll(ml=mO)&(dl=dO)age=yl-yO;else age=yl-yO-l;printf(nnThe studentV age is%du,age);getch();)14-23main()int m;printfCAninput a integer:);scanf(n%dn,&m);if(m%2=0)printf(n%d is event.,m);else printf(n%d is ord.n,m);getch
9、();)4-24main()int a,b,c,max;printf(Hninput a,b,c:);scanf(%d%d%d,&a,&b,&c);max=a;if(bmax)max=b;if(cmax)max=c;printf(nmax is%dn,max);getch();)4-25-1main()int x,y;printf(nninput x:);scanf(n%d,&x);if(x-5)&(x0)&(x-5)&(x10)if(x0)y=x+1;printf(Mnx is%d,y is%d,x,y);)else printf(ninput x is error!%cA007);getc
10、h();)(4-25-3main()int x,y;printf(nninput x:);scanf(%d,&x);if(x-5)&(x0)&(x10)y=x+l;printf(nx is%d,y is%d,x,y);getch();)4-25-4main()int x,y;printf(nninput x:);scanf(n%d,&x);switch(x)case-4:case-3:case-2:case-1:y=x;break;case 0:y=x-l;break;case 1 :case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9
11、:y=x+l;break;default:printf(Input x error!%c”,7);)printf(nnx is%d,y is%d,x,y);getch();第五章5-1 D 5-2 C 5-3 B 5-4 C 5-5 C 5-6 B 5-7 D 5-8 A5-9 D 5-10 D 5-11 5,4,6 5-1 2 死循环5-13-1 5-14 115-15 d=l,k+,k=0,xamin5-17main()int i,s=l,k=-l;for(i=l;i=50;i+)s=s+k*(2*i+l);k=-k;printf(ns=%dn,s);getch();)5-18-1main
12、()int i=l;double e=1.0,s=1.0;for(i=l;i=le-04)/*8 times*/s=s*i;i+;e=e+l/s;printf(,e=%10.6f,e);getch();5-19main()int y,k=O;for(y=1000;y=2000;y+)if(y%4=0&y%100!=0lly%400=0)printf(%1 Od,y);k+;if(k%3=0)printf(Hn);)getch();)5-20#include main()int i,j,n;printf(MInputn(l-10):H);do scanf(n%dn,&n);while(n10);
13、for(i=l;i=n;i+)for(j=l;j=40-i;j+)printf();for(j=l;j=2*i-l;j+)printf(*);printf(n);)for(i=n+1 ;i=2*n-l;i+)for(j=l;j=40-2*n+i;j+)printf();for(j=1 ;j=4*n-1 -2*i;j+)printf(*);printf(n);)getch();)第六章6-1 B 6-2 D 6-3 A 6-4 A 6-5 B 6-6 D 6-7 D 6-8 B6-9 A 6-10 A 6-11 C 6-12 26 6-13 1 6-14 ctype.h6-15 1 6-16 1
14、0A20B30C40D 6-17 7.29 101.298AB6-18 A7.29B 101.298 6-19 ABC6-20#include main()int k=0;char ch;while(ch=getchar()!=10)k+;printf(%4c%4d,ch,ch);if(k%3=0)printf(nn);)getch();6-21#include main()long k=0;char ch;while(ch=getchar()!=EOF)if(ch=0,&ch=,9)ch=ch-O;k=k*10+ch;)printf(n%ld,k);getch();6-22#include
15、main()int flag,k=O;char ch;while(ch=getchar()!=EOF)if(ch=10)k+;flag=O;else flag=l;)if(flag=l)k+;printf(n The line number is%dnu,k);getch();6-23#include main()int k=O;char ch;while(ch=getchar()!=10)if(ch=a,&ch=z)k+;printf(nn The lower letter number is%dnk);getch();6-24#include main()int i,j,n;printf(
16、Input line number:);scanf(%d,&n);for(i=l;i=n;i+)for(j=l;j=40-i;j+)printf();for(j=1;j=2*i-l;j+)printf(n%c,;64+i);printf(nn);)getch();)第七章7-1 C 7-2 C 7-3 B 7-4 C 7-5 A 7-6 D 7-7 A 7-8 127-9 9.000000 17-10 4 7-11 n=l,s 7-12=y,z*x 7-13 l,s*i,0,f(k)【7/4-1(错误)main()int m;printf(nInput a number:);scanf(n%d
17、,&m);m=fun(m);if(m=l)printf(HnThis number is a primer!n);elseprintf(nThis number is not a primer!n);getch();)fun(int n)int k,yes;for(k=2;k=n/2;k+)if(n%k=0)yes=0;else yes=l;return yes;)【714-2(正确)main()int m;printf(Input a number:);scanf(n%dn,&m);m=fun(m);if(m=l)printf(nnThis number is a primer!nH);el
18、seprintf(nnThis number is not a primer!n);getch();)fun(int n)int k,yes=l;for(k=2;k=n/2;k+)if(n%k=0)yes=0;return yes;7-15main()int a,b;printf(Input a&b:);scanf(%d%d,&a,&b);printf(,n%d%d=%d,a,b,mymod(a,b);getch();mymod(int a,int b)int z;z=a%b;return z;)7-16float fun(int n)return(1.0/n);main()int i,n,k
19、=l;float s=0.0;printf(Input n:n);scanf(,%d,&n);for(i=l;i=n;i+)s+=k*fun(i);k=-k;)printf(ns=%8,6f,s);getch();)7-17float f(int m)float t=1.0;int i;for(i=2;i=m;i+)t-=1.0/(i*i);return t;)main()int n;printfCInput n:H);scanf(d”,&n);printf(nt=%8.6fn,f(n);getch();)7-18#include float f(float x)float z;z=x*x-5
20、*x+4;return z;)main()float x,yl,y2,y3;printf(Input x:);scanf(n%f&x);yi=f(2);y2=f(x+15);y3=f(sin(x);printf(,yl=%10.4fnu,yl);printf(Hy2=%10.4fn,y2);printf(,y3=%10.4fn,y3);printf(n*END*);getch();)第八章8-1 A 8-21 B 8-3 B 8-4 C 8-5 B 8-6 B 8-7 C 8-8 D8-9 B 8-10 C 8-11 C 8-12 C 8-13 110 8-14 7 18-15 char*p=
21、ch;,p=&ch;,scanf(%c”,p);,p=a;,printf(%c,p);8-16 s=p+3;,s-=2,50,*(s+l),2,10 20 30 40 508-17-1fun(x,y)int*x,*y;int zl,z2;zl=*x+*y;z2=*x-*y;*x=zl;*y=z2;)main()int*a,*b,A,B;a=&A,b=&B;printf(input two numbers:);scanf(M%d%dn,a,b);printf(a,b=%d,%dn”,*a,*b);printf(before call function:nn);printf(a=%d b=%dn”
22、,*a,*b);fun(a,b);printf(after call function:nH);printf(a=%d b=%dn,*a,*b);getch();)8-17-2fun(x,y)float*x,*y;float zl,z2;zl=*x+*y;z2=*x-*y;*x=zl;*y=z2;)main()float*a,*b,A,B;a=&A;b=&B;printf(input two real numbers:);scanf(f%fa,b);printf(na,b=%f,%fn”,*a,*b);printf(nbefore call function:n);printf(a=%f b=
23、%fnH,*a,*b);fun(a,b);printf(after call function:nu);printf(a=%f b=%fn,*a,*b);getch();)8-18fun(int*a,int*b,int*c)int max,min;max=*a;min=*a;if(*b*a)max=*b;if(*bmax)max=*c;if(*cmin)min=*c;*a=max;*c=min;)main()int a,b,c;printf(Input a,b,c:);scanf(n%d%d%d,&a,&b,&c);printf(Hbefore call function:nM);printf
24、(na=%d b=%d c=%dn,a,b,c);fun(&a,&b,&c);printf(”after call function:nH);printf(max=%d min=%dn,a,c);getch();)第 9 章9-1 D 9-2 A 9-3 A 9-4 A 9-5 C 9-6 A 9-7 B 9-8 D9-9 C 9-10 C 9-11 C 9-12 D 9-13 D 9-14 A,C(?)9-15 A 9-16 A 9-17 C 9-18 C 9-19 9,0 9-20 6 9-21 129-22 3 9-23 2721 9-24-850,2,0 9-25 k=p,(k)【9-
25、26 c=getchar(),c-659-27#include main()char*s,a100;int i,k=0,num10=0;s=a;printf(nInput an number string:);scanf(%sn,s);while(*s!=,O,)if(isdigit(*s)&(*s,0,)num*s-49+;if(*s=48)num9+;s+;)for(i=0;i%3dn,i+l,numi);printf(H 0-%3dn,num91);printf(”*TOTAL*”);for(i=0;i=9;i+)k+=numi;printf(n%d”,k);getch();)9-28m
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 二级 语言 课后 练习题 答案
限制150内