C语言程序习题答案.doc
《C语言程序习题答案.doc》由会员分享,可在线阅读,更多相关《C语言程序习题答案.doc(27页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、C语言程序习题答案例1.1:/* Note:Your choice is C IDE */#include stdio.hvoid main()printf(This is a C program.n);return 0;例1.2:/* Note:Your choice is C IDE */#include stdio.hvoid main()char a,b,sum;a=123;b=456;sum=a+b;printf(sum is %cn,sum);return 0;例1.3:/* Note:Your choice is C IDE */#include stdio.h/主函数int m
2、ain()int max(int x,int y);int a,b,c;scanf(max=%d,%d,&a,&b);c=max(a,b);printf(max=%dn,c);return 0;/求两个整数中的较大者的max函数int max(int x,int y);int z;if(xy)z=x;else z=y;return(Z);例3.1:/* Note:Your choice is C IDE */#include stdio.hvoid main()float f,c;f=64.0;c=(5.0/9)*(f-32);printf(f%fnc%fn,f,c);return 0;例3.
3、2:/* Note:Your choice is C IDE */#include stdio.hvoid main()float p0=1000,r1=0.0036,r2=0.0225,r3=0.0198,p1,p2,p3;p1=p0*(1+r1);p2=p0*(1+r2);p3=p0*(1+r3/2)*(1+r3/2);printf(p1=%fnp2=%fnp3=%fn,p1,p2,p3);return 0;例3.3:/* Note:Your choice is C IDE */#include stdio.hvoid main()char c1,c2;c1=A;c2=c1+32;prin
4、tf(%cn,c2);printf(%dn,c2);return 0;例3.4:/* Note:Your choice is C IDE */#include stdio.h#include math.hvoid main()double a,b,c,s,area;a=3.67;b=5.43;c=6.21;s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c);printf(a=%ftb=%ftc=%fn,a,b,c);printf(area=%fn,area);return 0;例3.5:/* Note:Your choice is C IDE */#includ
5、e stdio.h#includemath.hvoid main()double a,b,c,disc,x1,x2,p,q;scanf(%lf%lf%lf,&a,&b,&c);disc=b*b-4*a*c;p=-b/(2.0*a);q=sqrt(disc)/(2.0*a);x1=p+q;x2=p-q;printf(x1=%7.2fnx2=%7.2fn,x1,x2);return 0;例3.6:/* Note:Your choice is C IDE */#include stdio.hvoid main()double a=1.0;printf(%10.15fn,a/3);return 0;例
6、3.7:/* Note:Your choice is C IDE */#include stdio.hvoid main()float a;a=10000/3.0;printf(%fn,a);return 0;例3.8:/* Note:Your choice is C IDE */#include stdio.hvoid main()char a=B,b=O,c=Y;putchar(a);putchar(b);putchar(c);putchar(n);return ;例3.9:/* Note:Your choice is C IDE */#include stdio.hvoid main()
7、char a,b,c;a=getchar();b=getchar();c=getchar();putchar(a);putchar(b);putchar(c);putchar(n);return 0;例3.10:/* Note:Your choice is C IDE */#include stdio.hvoid main()char c1,c2;c1=getchar();c2=c1+32;putchar(c2);return 0;例4.1:/* Note:Your choice is C IDE */#include stdio.h#include math.hvoid main()doub
8、le a,b,c,disc,x1,x2,p,q;scanf(%lf%lf%lf,&a,&b,&c);disc=b*b-4*a*c;if(discb)t=a;a=b;b=t;printf(%5.2f,%5.2fn,a,b);return 0;例4.3:/* Note:Your choice is C IDE */#include stdio.hvoid main()float a,b,c,t;scanf(%f,%f,%f,&a,&b,&c);if(ab)t=a;a=b;b=t;if(ac)t=a;a=c;c=t;if(bc)t=b;b=c;c=t;printf(%5.2f,%5.2f,%5.2f
9、n,a,b,c);return 0;例4.4:/* Note:Your choice is C IDE */#include stdio.hvoid main()char ch;scanf(%c,&ch);ch=(ch=A&ch=0);if(x0)y=1;elsey=0;elsey=-1;printf(x=%d,y=%d,x,y);return 0;习题4.8:/* Note:Your choice is C IDE */#include stdio.hvoid main()int grade;scanf(%d,&grade);if(grade=90)printf(A);elseif(grad
10、e=80)printf(B);elseif(grade=70)printf(C);elseif(grade=60)printf(D);elseprintf(E);return 0;例4.9:/* Note:Your choice is C IDE */#include stdio.hvoid main()int i,n;scanf(%d,&i); n=i/10000; i=1%10000; printf(n=%dn,n); n=i/1000; i=1%1000; printf(n=%dn,n); n=i/100; i=1%100; printf(n=%dn,n); n=i/10; i=1%10
11、; printf(n=%dn,n); n=i; printf(n=%dn,n); return 0;/* Note:Your choice is C IDE */#include stdio.hvoid main()long n,i;scanf(%d,&i); n=i/10000; i=i%10000; printf(n=%dn,n); n=i/1000; i=i%1000; printf(n=%dn,n); n=i/100; i=i%100; printf(n=%dn,n); n=i/10; i=i%10; printf(n=%dn,n); n=i; printf(n=%dn,n); ret
12、urn 0;/* Note:Your choice is C IDE */#include stdio.hvoid main()long n,a,b,c,d,e;printf(Please input a numbern); scanf(%d,&n);if(n/10000=1)a=n/10000;n=n%10000;b=n/1000;n=n%1000;c=n/100;n=n%100;d=n/10;e=n%10;printf(This is a 5weishun);printf(%dn%dn%dn%dn%dn,a,b,c,d,e);elseif(n/1000=1)b=n/1000;n=n%100
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 程序 习题 答案
限制150内