您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > 《C语言程序设计》阅读程序写结果试题汇总
记号:蓝色表示已做并且没有问题的红色表示已做但不是很顺手,需注意的黄色表示不会做黑色表示未做第四章:17阅读程序写结果试题第四章选择结构(共20道题)1.(于蕾)#includestdio.hvoidmain(){intx,y,t;x=7;y=9;if(xy){t=x;x=y;y=t;}printf(%d,%d\n,x,y);}运行结果:9,72.(于蕾)#includestdio.hvoidmain(){intx=1,a=2,b=3;switch(x){case1:a--;break;case2:b++;break;case3:a++;b++;}printf(\na=%d,b=%d\n,a,b);}运行结果:a=1,b=33.(于蕾)#includestdio.hvoidmain(){charch1='E';if(ch1='A')ch1++;elsech1+=32;printf(ch1=%c\n,ch1);}运行结果:ch1=F4.(于蕾)#includestdio.hvoidmain(){intx,y,t;x=5;y=3;if(xy){t=x;x=y;y=t;}printf(%d,%d\n,x,y);}运行结果:3,55.(王伟)#includestdio.hintmain(){inta,b,c,m;printf(Enterthreeintegers:);scanf(%d%d%d,&a,&b,&c);if(a=b)m=a;elsem=b;if(cm)m=c;printf(m=%d\n,m);return0;}输入:212223回车运行结果:m=216.(王伟)#includestdio.hintmain(){charch1='a',ch2='B',ch3='E';if(ch1ch2)if(ch2ch3)ch3++;else--ch3;printf(ch3=%c\n,ch3);return0;}运行结果:ch3=D7.(王伟)#includestdio.hintmain(){floatx,y;scanf(%f,&x);switch((int)x/10){case0:y=1.0;printf(y=%f\n,y);break;case1:y=2*x+1;printf(y=%f\n,y);break;case2:y=3*x*x+2;printf(y=%f\n,y);break;default:printf(Nodefinition.\n);}return0;}输入:15.3回车运行结果:y=31.6000008.(王伟)#includestdio.hintmain(){charch1='A',ch2='B';switch(ch1){!!特别要注意每个分句的最末尾有无break!!case'A':switch(ch2){case'B':printf(Good!\n);break;case'A':printf(Better!\n);break;}case'B':printf(Best!\n);break;}return0;}运行结果:Good!Best!9.(王锋)#includestdio.hvoidmain(){floatscore;score=100;if(score60)printf(E\n);elseswitch((int)score/10){case10:case9:printf(A\n);case8:printf(B\n);case7:printf(C\n);break;case6:printf(D\n);break;default:printf(Error\n);}}运行结果:ABC10.(王锋)#includestdio.hvoidmain(){inti=0,a=2;if(i==0)printf(“**”);elseprintf(“$$”);printf(“*”);}运行结果:***11.(王锋)#includestdio.hvoidmain(){intm=10,n=0,p=4,q=20;if(m)if(n)q=15-m;elseq=25+m;elseif(p)q=q+p;printf(“q=%d\n”,q);}运行结果:q=3512.(王锋)#includestdio.hvoidmain(){inta=1,b=0;switch(a){case1:switch(b){case0:printf(“**0**”);break;case1:printf(“**1**”);break;}case2:printf(“**2**”);break;}}运行结果:**0****2**13.(宋昕)#includestdio.hintmain(){inta=2,b=7,c=5;switch(a0){case1:switch(b0){case1:printf(@);break;case2:printf(!);break;}case0:switch(c==5){case1:printf(*);break;default:printf(#);break;}default:printf(&);}printf(\n);return0;}运行结果:*&14.(宋昕)#includestdio.hintmain(){inta=0,b=1,c=0,d=20;if(a)d=d-10;elseif(!b)if(!c)d=15;elsed=25;printf(d=%d\n,d);return0;}运行结果:d=2015.(宋昕)#includestdio.hintmain(){inta=1;switch(a){case0:printf(**0**);break;case1:printf(**1**);break;case2:printf(**2**);break;}return0;}运行结果:**1**16.(宋昕)#includestdio.hintmain(){intx,y;scanf(%d,&x);y=x12?x+10:x-12;printf(%d\n,y);return0;}输入:12回车运行结果:017.(宋昕)#includestdio.hintmain(){floatx,y;charop;doubler;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);return0;}输入:3.5回车运行结果:0.618.(王勇超)#includestdio.hvoidmain(){inta=7;if(a9||a10)a=a/3;elsea=a%3;printf(a=%d,a);}运行结果:a=219.(王勇超)#includestdio.hvoidmain(){inta=20;switch(a%3){case0:printf(0);case1:printf(1);case2:printf(2);default:printf(3);}printf(4);}运行结果:23420.(王勇超)#includestdio.hvoidmain(){inta=2,b=5,c=8,t;if(ab){t=a;a=b;b=t;}if(bc){t=b;b=c;c=t;}if(ab){t=a;a=b;b=t;}printf(%d,%d\n,a++,--c);}运行结果:8,1第五章循环结构共20道题1.(于蕾)#includestdio.hvoidmain(){intnumber,digit;number=1234;while(number!=0){digit=number%10;printf(%d,digit);number=number/10;}}运行结果:43212.(于蕾)#includestdio.h#defineN5voidmain(){inti;for(i=1;iN;i++)printf(%d\n,i*i);}运行结果:149163.(于蕾)#includestdio.hvoidmain(){inti,s,x;s=0;x=15;for(i=1;i=5;i++)if(x%i==0)s=s+i;printf(i=%d,s=%d\n,i,s);}运行结果:i=6,s=94.(于蕾)#includestdio.hvoidmain(){intcounter=1;while(counter=5){printf(%d\n,counter);counter++;}}运行结果:123455.(王伟)#includestdio.hintmain(){inti,sum,m,a;sum=0;m=5;for(i=0;i=3;i++){scanf(%d,&a);if(am)sum+=a;}printf(sum=%d\n,sum);return0;}输入:21083回车运行结果:sum=186.(王伟)#includestdio.hintmain(){inti,j,k;for(i=1;i=4;i++){for(j=1;j5-i;j++)printf();for(k=1;k=i;k++)printf(*);printf(\n);}return0;}运行结果:**********7.(王伟)#includestdio.hintmain(){inti,j;i=1;while(i5){for(j=1;j2*i+1;j++)printf(%c,'#');printf(\n);i++;}return0;}运行结果:####################8.(王伟)#includestdio.hintmain(){inti=10,m=0,n=0;do{if(i%2!=0)m=m+i;elsen=n+i;i--;}while(i=0);printf(m=%d,n=%d\n,m,n);return0;}运行结果:m=25,n=309.(王锋)#includestdio.hvoidmain(){intsum=0,n;scanf(%d,&n);while(n=5){sum+=n;n++;}printf(sum=%d,sum);}输入:1回车运行结果:sum=1510.(王锋)#includestdio.hvoidmain(){inti,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.(王锋)#includestdio.hvoidmain(){inta,b;for(a=1,b=1;a=100;a++){if(b20)break;if(b%4==1){b=b+4;continue;}b=b-5;}printf(a=%d\n,a);}运行结果:a=612.(王锋)#includestdio.hvoidmain(){chark;inti;for(i=1;i3;i++){scanf(%c,&k);switch(k){case'0':printf(another\n);case'1':printf(number\n);}}}输入:01回车运行结果:anothernumbernumber13.(宋昕)#includestdio.hintmain(){inti,s=0;for(i=1;i10;i++){s+=i*i;if(s10)break;}printf(i=%d,s=%d\n,i,s);return0;}运行结果:i=3,s=1414.(宋昕)#includestdio.hvoidmain(){charch;whil
本文标题:《C语言程序设计》阅读程序写结果试题汇总
链接地址:https://www.777doc.com/doc-3375431 .html