计算机c语言习题答案.docx
《计算机c语言习题答案.docx》由会员分享,可在线阅读,更多相关《计算机c语言习题答案.docx(68页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、C语言习题答案第1章1 .选择题(1) c (2) B (3) D2 .填空题(l)main (2) main (3)有穷性、确定性、有零个或多个输入、有一个或多个输出、有效性(4)顺序、分支和循环(5)自顶向下,逐步细化、模块化设计、结构化编码第2章1 .选择题BBCDA DDBBA BBDCB2、填空题(1)数字、字母、下划线(2)0(3)4、8(4)(a+b)*c/(a-b)(5)60(6)16(7) 3(8)6、4、2(9)0(10)10、6(11)5.500000(12)12、4(13) double (14)0(15)16(16)6.63、编程题(1) main ()printf(
2、int:%5dn Afloat :%5dnz/char:%5dn“double:%5dnlong:%5dn, sizeof (int), sizeof(float), sizeof(char), sizeof (double), sizeof(long);(2)ttinclude #define RAT 1.60934 main()float k=0.0;printf(input the km:); scanf(f,&k);printf (,nmile:%f,/, k*RAT);第3章1 .选择题(1)(10): DDCDCDCDBC2 .解析题(1)x=170, x=U M U 170, x
3、=U M U 252,170x=170, x=170 M M M ,x= M M U 170,x二%6da=513.789185, a= M M 513.79, a=513.78918457, a=513.78918457(2) a=3 U b=7x=8.5 M y=71.82cl=A M c2二 a 3.编程题(1) main()int x, y;scanf(%d%d,&x,&y);printf (商数二%d,余数=%d,x/y, x%y);system (z/pausezz);(2) main()double x, y, z, avg;scanf(/z%lf%lf%lf/z,&x,&y,&
4、z);avg=(x+y+z)/3;printf (. llfzz, avg, avg);system(pause);第4章1.选择题1 1)(10) CCAADCCABD2 .填空题ch=ch-32(1) ch=A& chCZ(2) x2x-ly二T(3) a+bc & a+cb & b+ca a=bac bc(4) mark/10k=lcase 9(5) x0c=x/10y!=-23.编程题(1)#include main()int x;printf (z,please input a number:/z);scanf(%d,&x);if(x%2=0) printf(/zx is a eve
5、n number);elseprintf(z/x is a oddnumber);)(2)#include main()int x, y;printf (/zplease input a number);scanf(d,&x);if (x=-5) printf(/zthe number is error );else if (x0)y=x;printf(%d, y);elseif (x=0)y=x-l;printf(%d,y);elseif (x10)y=x+l;printf(%d, y);else printf(the number is error );)(3)#include main(
6、) int a, m;printf (z/please input a number:z/);scanf (%d,&a);switch(a/10) case 0:case 1:case 2:m=l;break;case 3:m=2;break;case 4:m=3;break;case 5:m=4;break;default:m=5;break;)printf(%d, m);(4)#include main()float price,tax;printf(z/please input the price of product:);scanf(%f,&price);if (price10000)
7、 tax=price*。.05;else if (price5000) tax=price*。.03;else if (price1000) tax=price*。.02;else tax=0;printf (z,%fz/, tax);(5) #include main()float score;printf(z/please input the score of student:);scanf(%f,&score);if (score二85) printf (ZZVERY GOOD);else if(score=60) printf(GOOD); else printf(BAD);第5章1
8、.选择题(l)d (2) c (3)a (4)d(5)a(6)d(7)d(8)b(9)d(10)b(ll)c (12)b(13)d(14)a(15)c2 .填空题(1)=0 m=m/k k+(2)546(3)3*i-2(4)-二*=(5)852(6) j+i%j=0 j=i(7) sumk sum=k j-2(8) s=0p=l j=i3.改错题(1)第一处改正:For改为for第二处改正: ave=sum/4改为ave=sum/4.0(2)第一处改正:j=9第二处改正:m=100*i+10*j+k3.编程题(1)#include main()int s;float n, t, sum;t=l
9、; sum=0; n=l; s=l.0;while(n=100)sum=sum+t;n=n+l;s 二一 s;t=s/n;printf (/zsum=%10.6fn,sum);)(2)利用辗除法,直到b为。为止main() int p, r, n, m, temp;printf (input two integer n, m:); scanf (/z%d,%d,&n,&m);if(n0)xl=(x2+l)*2;/*第一天的桃子数是第2天桃子数加1后的2倍*/ x2=xl;day-;)printf (/zthe total is %dn,xl);(4)#include main()long in
10、t n=l;for (i=l;i=10;i+)n=n*i;printf (i%5=0?,z%2d!=%-101dnz,:2d!=%T01d,i, n);)(5)main()int m, s, i ;for(m=2;m1000;m+) s=0;for(i=l;im;i+)if (m%i)=0) s=s+i;if(s=m) printf (/z%d its factors are ,m); for(i=l;im;i+)if (m%i=0) printf (d,,i);printf(n);(6)#include main()int n, i, j;scanf(%d,&n);for(i=l;i=n;i
11、+) for(j=l;j=n+i-l;j+)if (j=n-i) printf (z/);else printf (*);printf(n);)(7)#includemain()|float xO, xl, x2, fxO, fxl, fx2; do printf (Z/Enter xl & x2:);scanf (%f,%f/z,&xl,&x2);fxl=xl*(2*xl-4)*xl+3)-6;fx2=x2*(2*x2-4)*x2+3)-6;while(fxl*fx20);do x0=(xl+x2)/2;fxO=xO*(2*x0-4)*x0+3)-6; if(fxO*fxl)=le-5);p
12、rintf (x二%6.2fn,xO);第6章1 .选择题CCDCC AADBD2 .写出程序的运行结果(1) sum=6(2) Max=9, row=l, col=0(3)01 02 103 210(4) -53、填空(1) i=j=k=0、i4、 j str, s 1s 2,str4、编程题(3)#include main()int a12, count=0, i;randomize ();for (i=0;i12;i+)a i=5+random(11);for(i=0;i12;i+)printf(%5d, ai);count+;if (count%4=0) printf (n)getch
13、O ;(4)main()|int a5=2,23,43,77,33);int max, min, i ;long sum=0L;int count=0;float av;max=min=a0;for(i=0;imax)max=ai;if (aimin)min=ai;av=(float)sum/5;for (i=0;iav)count+;printf(max:%dnmin:%dnav:%fncount:%d/z, max, min, av, count);getchO ;(5)main()intscore30=61,62,63,64,65,66,67,68,69,70,71,72,73,74,7
14、5,76,77,78,79,80,81,85,89,90,33,44,55,91,92,93);inti,count90=0, count80=0, count70=0, count 60=0;for(i=0;i30;i+)(printf (z/intput NO.%d student,sscore:/z, i+1);scanf(%d,score+i);for(i=0;i=90)(count90+;count80+;count70+;count60+;)else if(scorei=80)count80+;count70+;count60+;else if(scorei=70)(count70
15、+;count60+;)else if(scorei=60)(:count60+;printf(060:%dn6070:%dn7080:%dn 8090:%dn90100:%d,30-count60, count 60-count70, count70-count80,count80-co unt90, count90);printf (/zn60orhigher :%dn70orhigher:%dn80orhigher:%dn90orhigher :%dn/z, count60, count70, count80, count90);getchO ;(6)1、main ()(char a45
16、;int i, j, k;for(i=0;i45;i+)ai=for(i=0;i5;i+)(for(j=0;ji;j+)a9*i+j=;for (k=0;k5;k+) a9*i+j+k=*;)j=0;for(i=0;i45;i+)printf (级c, ai);j+;if (j%9=0) printf (n);getchO ;2、main()char a59;int i, j, k;for (i=0; i5; i+)for(j=0;j9;j+)aij-,;for(i=0;i5;i+)for(j=0;ji;j+)for (k=0;k5;k+) aij+k=*;)for(i=0;i5;i+)for
17、(j=0;j(xy?x:y)(9) str=abdef(10) 8,17(11) a=5a*a=25a*a*a=512(12)sixsi*ZTX XjX#xfx si*lx *A* vt*A*TX TX xTx XTTXsix slz *Jx *lx*Jx vl*TX TX*TX TX XlX TX#lz xfx *1* vt* vlx vl*TX TX XT* XT* XT*TXxfx sl*lx *A* vt*A*TX TX XTX XTTX#si* six xlzsi*TX XT* XT% XjX XT*3、编程题(1)long act(long n)if (n=l | n=0) ret
18、urn IL;elsereturn n*act(n-l);main()int n=3;printf(n!=%ld,act(n);getchO ;(2)void mmax(float a, int n); main()float a6;int i;for(i=l; i=5; i+)scanf;a0=l;mmax(a,5);printf (%f %fnz/, aa0, a0);)void mmax(float a, int n)if(naa0) a0=n;mmax (a, n-l);)(3)#include main()char a40;int i=0;for (;i=40;i+)scanf(;i
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 语言 习题 答案
限制150内