华中科技大学规范标准C语言知识程序设计及应用习题集标准答案.doc
《华中科技大学规范标准C语言知识程序设计及应用习题集标准答案.doc》由会员分享,可在线阅读,更多相关《华中科技大学规范标准C语言知识程序设计及应用习题集标准答案.doc(32页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、第二章一.选择题1.C 2.B D 3.A 4.A 5. D 6.C 7.D 8.C 9.A 10.D11.B 12.D 13.C 14.D 15.A16.B 17.A 18.B 100011 001111二.判断题1.错2.错3.错4.错三.填空题1. B 662. n1=%dnn2=%dn3. 0四.计算1(1) x|y = 0x002f(2) xy = 0x0026(3) x&y = 0x0009;(4) x+y = 0xffc6(5) x=4 0x00022(1) 6(2) 50(3) 1(4) 16(5) 1(6) 203(1) 0(2) 1(3) 1(4) 4(5) 8(6) 14
2、(1) 12(2) 0(3) 1(4) 27(5) 1(6) 6(7) 24(8) 27(9) 295(1) 0(2) 1(3) 1(4) 3(5) 2五.程序分析题程序1b=20 a=3600 程序2第三章一.填空题1.s=62.963.(1) scanf(%c,&c); (2) c-32 更好的答案:c-(a-A)2.1 main()int a,b;printf(please input a & b:);scanf(%d%d,&a,&b);printf(nmax is %dn,(ab)?a:b);2.2int max(int x,int y);main()int a,b,c,max;pri
3、ntf(please input a & b & c:);scanf(%d%d%d,&a,&b,&c);max=ab?a:b;max=cmax?c:max;printf(nmax is %dn,max);2.3main() int i=0,sum=0; while(i=100) sum+=i; i+; printf(1+2+3+.+100=%dn,sum);2.4main() int i; int a=10,b=-3; int c; printf(%6d%6d,a,b); for(i=2;i10;i+) c=3*b+a; printf(%6d,c); a=b; b=c; printf(n);2
4、.5main() int i; while(1) printf(please input a data(0:exit):); scanf(%d,&i); if(i=0) break; if(i%2=0) printf(the data %d is a even number.n,i); else printf(the data %d is a odd number.n,i); 2.6#include main() int i; int a=8,b=1; int sum=0; for(i=0;i10;i+) b+=3; sum += a; a+=b; printf(a%8d b:%8dn,a,b
5、); printf(The Sum Of Is:%dn,sum);2.7#include main() float x,y; printf(please input x:); scanf(%f,&x); if(x1.0) y=x; else if(x10) y=2*x-1; else y=3*x-11; printf(y=%fn,y);2.8#include main() long a,i,b,a1; while(1) printf(please input data(1-99999):); scanf(%ld,&a); printf(a:%ldn,a); if(a=100000) break
6、; i=0; a1=0; while(a!=0) b=a%10; printf(%8d,b); a/=10; i+; a1=a1*10+b; printf(n i:%ld a1:%ldn,i,a1); 2.9#include #include #include main() int a,b,i,k=0; randomize(); a=random(1001);/*create a random data(0-1000)*/ for(i=0;ib) k+; printf(n%d:Smaller,guess again!n,k); else if(ab) k+; printf(n%d:Bigger
7、,guess again!n,k); else printf(nYou guess right,congraturation!) ; printf(nYou have guessed %d times,k); break; if(k=20) printf(nsorry,you failed!);2.10#include main() int a,b,c; int num; for(a=0;a10;a+) for(b=0;b10;b+) for(c=1;c10;c+) num=a*100+b*10+c;if(num%3=0)&(a=5|b=5|c=5) printf(%8d,num); prin
8、tf(nnn);2.11#include main() int i; int a,b; printf(please input a,b:); scanf(%d%d,&a,&b); for(i=a0;i-) if(a%i=0&b%i=0) printf(The max=%d,i); break; for(i=ab?a:b;i0;i+) if(i%a=0&i%b=0) printf(nThe min=%d,i); break; 2.12#include main() int a,k=0; printf(please input data:); scanf(%d,&a); while(a%2=0)
9、a=a/2; k+; printf(nthe number of factor(2) is %d,k);2.13main() long i,t=1; long sum=0; for(i=1;i=10;i+) t*=i; sum+=t; printf(%ld!=%ldn,i,t); printf(sum:%ldn,sum); 2.14#include void main() int i,x=0; for(i=9;i=1;i-) x=2*(x+1); printf(The first day:%d,x);2.15#include #define PI 3.141593main() float r,
10、h; float v; printf(please input r,h:); scanf(%f%f,&r,&h); v=1.0/3*PI*r*r*h; printf(V=%.2f,v);2.16#include#includemain() long int sn=0; long int m=0,t=0; int a,n,i; printf(please input a n:); scanf(%d%d,&a,&n); for(i=0;in;i+) m=m*10+a; sn+=m; printf(a+aa+aaa+.+aa.a=%ldnn,sn);2.17#include main() int k
11、; printf(please input k:); do scanf(%d,&k); if(k=0&k=6) break; while(1); switch(k) case 0:printf(Sunday.n);break; case 1:printf(Monday.n);break; case 2:printf(Tuesday.n);break; case 3:printf(Wednesday.n);break; case 4:printf(Thursday.n);break; case 5:printf(Friday.n);break; case 6:printf(Saturday.n)
12、;break; 2.18#include main() int i; double x,a,b=1,sum=1; printf(please input x:); scanf(%lf,&x); a=x; for(i=1;a/b=1e-6;i+) sum=sum+a/b; a=a*x; b=(i+1)*b; printf(nsum=%lf,sum);2.19#include #include main() float a,x1,x2; printf(input a:); scanf(%f,&a); x1=1.0; while(1) x2=1.0/2*(x1+a/x1); if(fabs(x2-x
13、1)1e-5) break; x1=x2; printf(sqrt(a)=%f,x2);第四章写出下列程序输出结果1.no 1 a=1no 1 a=0no 1 a=1no 1 a=02.a=0 b=0 c=0a=1 b=0 c=0a=2 b=0 c=03.main:x=5,y=1,n=1func:x=6,y=21,n=11main:x=5,y=1,n=11func:x=8,y=31,n=21第五章1.D2.D3.C4.65.CDABC6.(1)j+=2 (2)ai=0&si=912. (1)0 (2)str1i-str2i5.1#includeint fun();int fun() int a
14、33,sum; int i,j; sum=0;/*error*/ for(i=0;i3;i+) for(j=0;j3;j+) scanf(%d,&aij);/*error*/ for(i=0;i3;i+) sum=sum+aii; printf(sum=%dn,sum);void main() fun();5.2#include void main( void ) float Num10; float Input,GetNum11; int i,j; float a=6;for(i=0; i10; i+) Numi=a; a=a+7.5;Loop1: printf(Please input a
15、 Number(0-80) Input=); scanf(%f,&Input);if(Input70)=1)goto Loop1;for(i=0; i10; i+ )if(InputNumi)goto Loop2;Loop2: for(j=0; ji; j+ ) GetNumj=Numj;GetNumj=Input;for(j=i; j=10; j+,i+)GetNumj+1=Numi;for(j=0; j11; j+ )printf(%3.3f ,GetNumj);5.3#include stdio.h#include stdlib.hmain()int a1,a2,a3,a4,a5,a6,
16、a7,a8,a9;int a3;int i;for(;)for (i=0;i3;i+)ai=rand()%3;while(a0!=a1) & (a0!=a2) & (a1!=a2)/*get three different numbers 0,1,2*/a1=a0+1;/*divide 19 into three groups,a1a3,a4a6,a7a9*/a2=a1+1;a3=a2+1;a4=a1+3;a5=a2+3;a6=a3+3;a7=a1+6;a8=a2+6;a9=a3+6;/* make sure that each line and each row is made up wit
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 华中科技大学 规范 标准 语言 知识 程序设计 应用 利用 运用 习题集 标准答案
限制150内