收藏 分销(赏)

2023年二级C语言程序设计教程课后习题答案高教版.doc

上传人:精*** 文档编号:3243637 上传时间:2024-06-26 格式:DOC 页数:30 大小:84.54KB
下载 相关 举报
2023年二级C语言程序设计教程课后习题答案高教版.doc_第1页
第1页 / 共30页
2023年二级C语言程序设计教程课后习题答案高教版.doc_第2页
第2页 / 共30页
2023年二级C语言程序设计教程课后习题答案高教版.doc_第3页
第3页 / 共30页
2023年二级C语言程序设计教程课后习题答案高教版.doc_第4页
第4页 / 共30页
2023年二级C语言程序设计教程课后习题答案高教版.doc_第5页
第5页 / 共30页
点击查看更多>>
资源描述

1、二级C语言程序设计教程课后习题答案(高教版)刊登日期:3月3日 已经有4929位读者读过此文第一章【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】B【2-9】A【2-10】C【2-11】B【2-12】B【2-13】A【2-14】11,12【2-15】4.2,4.2【2-16】,定义阐明,执行语句【2-17】关键字,顾客标识符【2-18】int,float,double【2-19】float a=b=1;【2-20】存贮单元【2-21】3.5【2-22】a

2、*b/c,a/c*b,b/c*a【2-23】把10赋予变量s【2-24】bit,0/1【2-25】8,127,01111111,-128,10000000(补码) 【2-26】32767,-32768,1111,0000【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 */*/ r=5.0; s=3.14159*r*r; printf(%fn,s)【2-28-2】(对旳)#include stdio

3、.h;main() /* main function */ float r,s;/* r is radius,s is area of circular */ r=5.0; s=3.14159*r*r; printf(%fn,s); 【2-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.0 v=a*b*c; printf(%fn,v)【2-29-2】(对旳)#include main() /* mai

4、n function */ float a,b,c,v;/* a,b,c are sides,v is volume of cube */ a=2.0;b=3.0;c=4.0; v=a*b*c; printf(%fn,v);第三章【3-1】C 【3-2】C 【3-3】D 【3-4】C 【3-5】D 【3-6】B 【3-7】C 【3-8】D 【3-9】A 【3-10】B 【3-11】C 【3-12】D 【3-13】D【3-14】C 【3-15】C 【3-16】C 【3-17】C 【3-18】A 【3-19】C【3-20】B 【3-21】(1)-200 2500(2)i=-200,j=2500(3

5、)i=-200/(换行)j=2500【3-22】12,0,0【3-23】一条语句,;【3-24】;【3-25】100 25.81 1.89234,100/25.81/1.89234,100/25.81 1.89234【3-26】x=127,x= 127,x= 177,x= 7f,x= 127【3-27】x=127,x=127 ,x=$127 ,x=$000127,x=%06d【3-28】a=513.789215,a= 513.79,a= 513.78921500,a= 513.78921500【3-29-1】(错误)main double a,b,c,s,v; printf(input a,b

6、,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() float a,b,c,s,v; printf(input 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(s=%f,v=%fn,s,v);【3-30】main() int h,m; h=560/60; m=560%60; printf(%d

7、h:%dm,h,m); getch();【3-31】main() int m,n; printf(input m & n:); scanf(%d%d,&m,&n); printf(n%d,%dn,m/n,m%n); getch();【3-32】main() double x,y,z,s; printf(input x,y,z:); scanf(%lf%lf%lf,&x,&y,&z); s=(x+y+z)/3.0; printf(nAverage=%6.1lfn,s); getch();【3-33】main() int a,b,c,t; printf(Input a,b,c:); scanf(%

8、d%d%d,&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】A【4-9】D【4-10】A【4-11】非零,零【4-12】,= =,!=【4-13】!,&,| 【4-14】!,关系运算符,&,| 【4-15】!【4-16】(A)a=b|a4【4-17】1【4-18】xm0)|(m1=m0)&(d1=d0) age=y1-y0; else age=y1-y0-1; printf(nThe student a

9、ge is %d,age); getch();【4-23】main() int m; printf(ninput a integer:); scanf(%d,&m); if (m%2=0) printf(n%d is event.,m); else printf(n%d is ord.,m); getch();【4-24】main() int a,b,c,max; printf(ninput a,b,c:); scanf(%d%d%d,&a,&b,&c); max=a; if (bmax) max=b; if (cmax) max=c; printf(max is %d,max); getch

10、();【4-25-1】main() int x,y; printf(ninput x:); scanf(%d,&x); if(x-5)&(x0)&(x-5)&(x10) if (x0) y=x+1; printf(nx is %d ,y is %d,x,y); else printf(input x is error !%c,007); getch();【4-25-3】main() int x,y; printf(ninput x:); scanf(%d,&x); if (x-5)&(x0)&(x10) y=x+1; printf(nx is %d ,y is %d,x,y); getch()

11、;【4-25-4】main() int x,y; printf(ninput x:); scanf(%d,&x); switch(x) case -4: case -3: case -2: case -1:y=x;break; case 0 :y=x-1;break; case 1 : case 2 : case 3 : case 4 : case 5 : case 6 : case 7 : case 8 : case 9 :y=x+1;break; default :printf(Input x error !%c,7); printf(nx is %d ,y is %d,x,y); get

12、ch();第五章【5-1】D【5-2】C【5-3】B【5-4】C【5-5】C【5-6】B【5-7】D【5-8】A【5-9】D【5-10】D【5-11】5,4,6【5-12】死循环【5-13】-1【5-14】11【5-15】d=1,k+,k=0,xamin【5-17】main() int i,s=1,k=-1; for (i=1;i=50;i+) s=s+k*(2*i+1); k=-k; printf(s=%d,s); getch();【5-18-1】main() int i=1; double e=1.0,s=1.0; for(i=1;i=1e-04) /* 8 times */ s=s*i;

13、 i+; e=e+1/s; printf(e=%10.6f,e); getch();【5-19】main() int y,k=0; for(y=1000;y=;y+) if (y%4=0&y%100!=0|y%400=0) printf(%10d,y);k+; if (k%3=0) printf(n); getch();【5-20】#include main()int i,j,n; printf(Input n (1-10):); do scanf(%d,&n); while (n10);for (i=1;i=n;i+) for (j=1;j=40-i;j+) printf( ); for (

14、j=1;j=2*i-1;j+) printf(*); printf(n); for (i=n+1;i=2*n-1;i+) for (j=1;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】B【6-9】A【6-10】A【6-11】C【6-12】26【6-13】1【6-14】ctype.h【6-15】1 【6-16】10A20B30C40D【6-17】7.29 101.298AB【6-1

15、8】A7.29B101.298【6-19】A B C 【6-20】#include main() int k=0;char ch; while(ch=getchar()!=10) k+; printf(%4c%4d,ch,ch); if(k%3=0) printf(n); getch();【6-21】#include main() long k=0;char ch; while(ch=getchar()!=EOF) if (ch=0&ch=9) ch=ch-0; k=k*10+ch; printf(%ld,k);getch();【6-22】#include main() int flag,k=

16、0;char ch; while(ch=getchar()!=EOF) if (ch=10) k+;flag=0; else flag=1; if (flag=1) k+; printf(n The line number is %dn,k);getch();【6-23】#include main() int k=0;char ch; while(ch=getchar()!=10) if (ch=a&ch=z) k+; printf(n The lower letter number is %dn,k);getch();【6-24】#include main() int i,j,n; prin

17、tf(Input line number :); scanf(%d,&n); for(i=1;i=n;i+) for (j=1;j=40-i;j+) printf( ); for(j=1;j=2*i-1;j+) printf(%c,64+i); printf(n); getch();第七章【7-1】C【7-2】C【7-3】B【7-4】C【7-5】A【7-6】D【7-7】A【7-8】12【7-9】9.000000【7-10】4【7-11】n=1,s【7-12】=y,z*x【7-13】1,s*i,0,f(k)【7-14-1】(错误)main()int m; printf(Input a numbe

18、r:); scanf(%d,&m); m=fun(m); if (m=1) printf(nThis number is a primer !n); else printf(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=1; return yes;【7-14-2】(对旳)main()int m; printf(Input a number:); scanf(%d,&m); m=fun(m); if (m=1) printf(

19、nThis number is a primer !n); else printf(nThis number is not a primer !n);getch();fun(int n) int k,yes=1; for (k=2;k=n/2;k+) if (n%k=0) yes=0; return yes;【7-15】main()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; 【

20、7-16】float fun(int n)return (1.0/n);main()int i,n,k=1; float s=0.0; printf(Input n:); scanf(%d,&n); for(i=1;i=n;i+) s+=k*fun(i); k=-k; printf(ns=%8.6f,s); getch();【7-17】float 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; printf(Input n:); scanf(%d,&n); printf(nt=%

21、8.6f,f(n); getch();【7-18】#include float f(float x) float z; z=x*x-5*x+4; return z;main()float x,y1,y2,y3; printf(Input x:); scanf(%f,&x); y1=f(2); y2=f(x+15); y3=f(sin(x); printf(y1=%10.4fn,y1); printf(y2=%10.4fn,y2); printf(y3=%10.4fn,y3); printf(n* END *); getch();第八章【8-1】A【8-2】B【8-3】B【8-4】C【8-5】B

22、【8-6】B【8-7】C【8-8】D【8-9】B【8-10】C【8-11】C【8-12】C【8-13】110【8-14】7 1【8-15】char *p=ch;,p=&ch;,scanf(“%c”,p);,p=a;,printf(“%c”,p);【8-16】s=p+3;,s-=2,50,*(s+1),2,10 20 30 40 50【8-17-1】fun(x,y)int *x,*y;int z1,z2; z1=*x+*y; z2=*x-*y; *x=z1;*y=z2;main()int *a,*b,A,B; a=&A,b=&B; printf(input two numbers:); scan

23、f(%d%d,a,b); printf(a,b=%d,%dn,*a,*b); printf(before call function:n); printf(a=%d b=%dn,*a,*b); fun(a,b); printf(after call function:n); printf(a=%d b=%dn,*a,*b); getch();【8-17-2】fun(x,y)float *x,*y;float z1,z2; z1=*x+*y; z2=*x-*y; *x=z1;*y=z2;main()float *a,*b,A,B; a=&A;b=&B; printf(input two real

24、 numbers:); scanf(%f%f,a,b); printf(a,b=%f,%fn,*a,*b); printf(before call function:n); printf(a=%f b=%fn,*a,*b); fun(a,b); printf(after call function:n); printf(a=%f b=%fn,*a,*b); getch();【8-18】fun(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=

25、*c; *a=max;*c=min;main()int a,b,c; printf(Input a,b,c:); scanf(%d%d%d,&a,&b,&c); printf(before call function:n); printf(a=%d b=%d c=%dn,a,b,c); fun(&a,&b,&c); printf(after call function:n); 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】D【9-9】C【9-10】C【9-11】C【9-

26、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】12【9-22】3【9-23】2721【9-24】-850,2,0【9-25】k=p,(k) 【9-26】c=getchar(),c-65【9-27】#include main() char *s,a100; int i,k=0,num10=0; s=a; printf(Input an number string:); scanf(%s,s); while(*s!=0) if (isdigit(*s)&(*s0) num*s-49+; if (*s

27、=48) num9+; s+; for (i=0;i%3dn,i+1,numi); printf( 0-%3dn,num9); printf(* TOTAL *n); for (i=0;i=9;i+) k+=numi; printf( %d ,k); getch();【9-28】move(int a10,int n)int i; for (i=n;i10;i+) ai-1=ai;a9=0;main()int x10,i,n; printf(input 10 number:); for(i=0;i10;i+) scanf(%d,&xi); printf(ninput the N:); scanf

28、(%d,&n); move(x,n); printf(nAfter move tne member list is :n); for (i=0;i10;i+) printf(%d ,xi); getch();【9-29】main()int a100=0,b100=0,i,j; printf(nInput the number list (end with 32767) :n ); for(i=0;i100;i+) scanf(%d,&ai); if ( ai=32767) break; i-; odd(a,b,i); printf(narray B :n); for (i=0;i100;i+)

29、 if (bi!=0) printf(%d ,bi); else break; getch();odd(int a100,int b100,int n) int i,j=0; for(i=0;i=n;i+) if(ai%2!=0) bj+=ai;【9-30】#include sort(char s,int n)int i,j,p,t; for(j=0;j(n-1);j+) p=j; for(i=j+1;in;i+) if(sp=ai-1) i+; while(ai-1!=32767); printf(nInput inserted number:); scanf(%d,&n); p=a; in

30、sert(p,n); p=a+1; printf(nOutput array a:n); do if (*p!=32767) printf(%d ,*p+); while (*p!=32767); getch();insert( int *q,int n) int *k; k=q; while (*q!=32767) q+; *(q+1)=*q; while(qk) if (n*(q-1) *q=n;break; else q-;*(q+1)=*q; 【9-32】main()int n,a16=0,*p; printf(nInput an number:); scanf(%d,&n); p=a

31、; change(a,n,p); printf(n=%dn,n); while(p=a+15) printf(%d,*p+);change(x,n,p)int x16,n,*p; p=x+15;*p=0; if(n=0) return(0); while(n!=0) *p=n%2; p-; n/=2; 【9-33】#include main()int a15,*p,i; p=a; frandm(a); printf(nThe array a is:); for(i=0;i15;i+) printf(%d ,*p+);frandm( a);int k=0,i,x,*q; for (i=0;i15

32、;i+) ai=20; while(k15) x=rand()%20; for (i=0;i15;i+) if (ai=x ) continue; else ak+=x; 【9-34】#define N 20main()int aNN,xN=0,yN=0,i,j,m,sum=0; printf(n Input N (20) :); scanf(%d,&m); printf(n Input array a%d%d:n,m,m); for(i=0;im;i+) for(j=0;jm;j+) scanf(%d,&aij); xi+=aij;yj+=aij; if (i=j ) sum+=aii; p

33、rintf(n After compute :n); for (i=0;im;i+) for (j=0;jm;j+) printf(%5d,aij); printf(%5dn,xi); for (i=0;im;i+) printf(%5d,yi);printf(nnSum=%dn,sum);getch();【9-35】#define N 20main()int aNN,bNN,cNN,m,n,i,j; printf(n Input m,n (20) :); scanf(%d%d,&m,&n); printf(n Input array A%d%d:n,m,n); for(i=0;im;i+)

34、for(j=0;jn;j+) scanf(%d,&aij); printf(n Input array B%d%d:n,m,n); for(i=0;im;i+) for(j=0;jn;j+) scanf(%d,&bij);cij=aij+bij; printf(n After compute array C:n); for (i=0;im;i+) for (j=0;jn;j+) printf(%5d,cij); printf(n); getch();【9-36】main()int i,j,k; printf(n * A MULTIPLICATION TABLE *n); printf( ); for(i=1;i10;i+) printf(%3d),i); printf(n -n); for(i=1;i10;i+) for(j=0;j10;j+) if(j=0) printf( %d),i); else printf(%5d,i*j); printf(n); printf(n -n); getch();【9-37】#include stdio.h#include stdlib.hmain()static int

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 考试专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服