《C语言学习知识程序设计》阅读程序写结果试题汇总.doc
《《C语言学习知识程序设计》阅读程序写结果试题汇总.doc》由会员分享,可在线阅读,更多相关《《C语言学习知识程序设计》阅读程序写结果试题汇总.doc(72页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-阅读程序写结果试题第四章 选择结构 (共20道题)1. (于蕾)#include void main( ) int x,y,t;x=7;y=9;if(xy) t=x;x=y;y=t;printf(%d,%dn , x,y );运行结果:9,72. (于蕾)#include void main( ) int x=1,a=2,b=3; switch(x) case 1: a-; break; case 2: b+; break; case 3: a+;b+; printf(na=%d,b=%dn,a,b);运行结果:a=1,b=33. (于蕾)#include void main( ) char
2、 ch1 = E; if(ch1 = A) ch1+; else ch1+=32; printf(ch1 = %cn, ch1);运行结果:ch1= F 4. (于蕾)#include void main( ) int x,y,t;x=5;y=3;if(xy) t=x;x=y;y=t;printf(%d,%dn , x,y );运行结果:3,55. (王伟)#include int main()int a,b,c,m;printf(Enter three integers:);scanf(%d%d%d,&a,&b,&c);if(a=b)m=a;elsem=b;if(cm)m=c;printf(
3、m=%dn,m);return 0;输入:21 22 23运行结果:m=216. (王伟)#include int main()char ch1=a,ch2=B,ch3=E;if(ch1ch2)if(ch2ch3)ch3+;else-ch3;printf(ch3=%cn,ch3);return 0;运行结果:ch3=D7. (王伟)#include int main()float x,y;scanf(%f,&x);switch(int)x/10)case 0: y=1.0;printf(y=%fn,y);break;case 1: y=2*x+1;printf(y=%fn,y);break;c
4、ase 2: y=3*x*x+2;printf(y=%fn,y);break;default:printf(No definition.n); return 0;输入:15.3运行结果:y=31.6000008. (王伟)#include int main()char ch1=A,ch2=B;switch(ch1)case A:switch(ch2)case B: printf(Good!n);break;case A: printf(Better!n);break;case B: printf(Best!n); break;return 0;运行结果:Good!Best!9 (王锋)#inc
5、lude void main() float score;score = 100;if (score60) printf(En); else switch( ( int ) score / 10 ) case 10: case 9: printf(An); case 8: printf(Bn); case 7: printf(Cn); break; case 6: printf(Dn); break; default: printf(Errorn); 运行结果:ABC10 (王锋)#include void main()int i=0,a=2;if(i=0)printf(“*”);elsepr
6、intf(“$”);printf(“*”);运行结果:*11. (王锋)#include void main()int m=10,n=0,p=4,q=20;if (m) if (n) q=15-m;else q=25+m;else if (p) q=q+p;printf(“q=%dn”,q); 运行结果:q=3512. (王锋)#includevoid main()int a=1,b=0;switch(a)case 1: switch (b)case 0: printf(“*0*”); break; case 1:printf(“*1*”);break;case 2: printf(“*2*”
7、);break;运行结果:*0*2*13. (宋昕)#includeint main( ) int a=2,b=7,c=5; switch (a0) case 1: switch (b0) case 1: printf(); break ; case 2: printf(!); break ; case 0: switch (c=5) case 1: printf(*) ; break ; default : printf(#) ; break ; default : printf(&); printf(n); return 0;运行结果:*&14. (宋昕)#includeint main(
8、) int a=0,b=1,c=0,d=20; if(a) d=d-10; else if (!b) if(!c) d=15; else d=25; printf(d=%dn,d); return 0;运行结果:d=2015. (宋昕)#includeint main() int a=1; switch(a) case 0: printf(*0*);break; case 1:printf(*1*);break; case 2:printf(*2*);break; return 0;运行结果:*1*16. (宋昕)#include int main() int x, y; scanf(%d,&
9、x); y = x12 ? x + 10 : x - 12; printf(%dn, y); return 0;输入:12运行结果:017. (宋昕)#include int main() float x, y; char op; double r; scanf(%c%f%f,&op,&x,&y); switch(op) case +: r = x + y; break; case -: r = x - y; break; case *: r = x * y; break; case /: r = x / y; break; printf(%.1f, r); return 0;输入:3.5运行
10、结果:0.618. (王勇超)#include stdio.hvoid main( ) int a=7; if(a9 | a10) a=a/3; else a=a%3; printf(a=%d, a);运行结果:a=219. (王勇超)#includevoid main() int a=20; switch(a%3) case 0: printf(0); case 1: printf(1); case 2: printf(2); default: printf(3); printf(4);运行结果:23420. (王勇超)#include void main()int a=2,b=5,c=8,
11、t;if ( a b ) t = a; a = b; b = t; if ( b c ) t = b; b = c; c = t; if ( a b ) t = a; a = b; b = t; printf( %d,%dn, a+, -c );运行结果:8,1第五章 循环结构 共20道题1. (于蕾)#include void main() int number , digit; number = 1234; while ( number != 0 ) digit = number%10 ;printf( %d , digit ) ;number = number / 10 ;运行结果:43
12、212. (于蕾)#include #define N 5void main( )int i; for(i=1;iN;i+) printf(%dn,i*i);运行结果:149163. (于蕾)#includevoid main( ) int i,s,x; s=0; x=15; for(i=1;i=5;i+) if (x%i=0)s= s + i; printf(i=%d,s=%dn,i,s);运行结果:i=6,s=94. (于蕾)#include void main()int counter=1; while(counter = 5) printf(%d n, counter ); count
13、er+;运行结果:123455 (王伟)#includeint main()int i,sum,m,a;sum=0;m=5;for(i=0;im)sum+=a;printf(sum=%dn,sum);return 0;输入:2 10 8 3运行结果:sum=186. (王伟)#includeint main()int i,j,k;for(i=1;i=4;i+)for (j=1;j5-i;j+)printf( );for(k=1;k=i;k+)printf(*);printf(n);return 0;运行结果: * * *7. (王伟)#include int main()int i,j;i=1
14、;while(i5)for(j=1;j2*i+1;j+)printf(%c,#);printf(n);i+;return 0;运行结果:#8. (王伟)#include int main()int i=10,m=0,n=0;doif(i%2!=0)m=m+i;elsen=n+i;i-;while(i=0);printf(m=%d,n=%dn,m,n);return 0;运行结果:m=25,n=309 (王锋)#include void main() int sum=0,n; scanf(%d,&n); while(n=5) sum+=n; n+;printf(sum=%d,sum);输入:1运
15、行结果:sum=1510 (王锋)#include void main()int i, j;for(i=2;i=0;i-)for(j=1;j=i;j+)printf(*);for(j=0;j=2-i;j+)printf(!);printf(n);运行结果:*!*!11 (王锋)#include void main()int a,b;for(a=1,b=1;a20) break;if(b%4=1)b=b+4;continue;b=b-5;printf(a=%dn,a);运行结果:a=612 (王锋)#include void main( )char k; int i; for(i=1;i3;i+
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C语言学习知识程序设计 语言 学习 知识 程序设计 阅读 浏览 程序 结果 试题 汇总
限制150内