《华中科技大学标准C语言程序设计及应用习题答案 .》由会员分享,可在线阅读,更多相关《华中科技大学标准C语言程序设计及应用习题答案 .(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; 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(We