《C语言程序设计》阅读程序写结果试题汇总2022.pdf
《《C语言程序设计》阅读程序写结果试题汇总2022.pdf》由会员分享,可在线阅读,更多相关《《C语言程序设计》阅读程序写结果试题汇总2022.pdf(71页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、阅读程序写结果试题阅读程序写结果试题第四章第四章 选择结构选择结构(共(共 2020 道题)道题)1.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)case1:a-;break;case2:b+;break;case3:a+;b+;printf(na=%d,b=%dn,a,b);运行结果:a=1,b=33.#include void main()char ch1=E;if(ch1
2、=A)ch1+;elsech1+=32;printf(ch1=%cn,ch1);运行结果:ch1=F4.#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(m=%dn,m);return 0;输入:21 22 23运行结果:m=216.#in
3、clude 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;case 2:y=3*x*x+2;printf(y=%fn,y);break;default:printf(No
4、 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#include void main()float score;score=100;if(score60)printf(En);elseswitch(
5、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(“*”);elseprintf(“$”);printf(“*”);运行结果:*11.(王锋)#includevoid main()int m=10,n=0,p=4,q=20;if(m)if(n)q=15-m;elseq=25+m;e
6、lse if(p)运行结果:q=3512.(王锋)#includevoid main()int a=1,b=0;switch(a)case 1:switch(b)case 0:printf(“*0*”);break;case 2:printf(“*2*”);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(“*1*”);bre
7、ak;q=q+p;printf(“q=%dn”,q);case 1:printf(*);break;default:printf(#);break;default:printf(&);printf(n);return 0;运行结果:*&14.(宋昕)#includeint main()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
8、*);break;case 1:printf(*1*);break;case 2:printf(*2*);break;return 0;运行结果:*1*16.(宋昕)#include int main()int x,y;scanf(%d,&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
9、*:r=x*y;break;case/:r=x/y;break;printf(%.1f,r);return 0;输入:3.5运行结果:0.618.(王勇超)#include stdio.hvoid main()int a=7;if(a9|a10)a=a/3;elsea=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.(
10、王勇超)#include void main()int a=2,b=5,c=8,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第五章第五章 循环结构循环结构共共 2020 道题道题1.(于蕾)#include void main()intnumber,digit;number=1234;while(number!=0)digit=number%10;printf(%d,digit);number=number/10;运行结果:43212.(于蕾)#include#d
11、efine 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);counter+;运行结果:123455(王伟)#includeint main()int i,
12、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;while(i5)for(j=1;j2*i+1;j+)printf(%c,#);printf(n);i+
13、;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 voidmain()int sum=0,n;scanf(%d,&n);while(n=5)sum+=n;n+;printf(sum=%d,sum);输入:1运行结果:sum=1510(王锋)#include void main()int i,j;for(i=2;i=0;i-)fo
14、r(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+)scanf(%c,&k);switch(k)case 0:printf(anothern);case 1:printf(numbern)
15、;输入:01运行结果:anothernumbernumber13.(宋昕)#include int main()int i,s=0;for(i=1;i 10)break;printf(i=%d,s=%dn,i,s);return 0;运行结果:i=3,s=1414.(宋昕)#include void main()char ch;while(ch=getchar()!=n)if(ch=A&ch=a&ch=z)ch=ch-32;printf(%c,ch);输入:ABCdef运行结果:abcDEF15.(宋昕)#include int main()int a,b;for(a=1,b=1;a=9)br
16、eak;if(b%3=1)b+=3;continue;b-=5;printf(%d,%dn,a,b);return 0;运行结果:4,1016.(宋昕)#includeint main()int i=0,j=0;while(i 10)i+;while(j+10);printf(i=%d,j=%dn,i,j);return 0;运行结果:i=10,j=1117.(王勇超)#include stdio.hvoid main()int i,j,t;for(i=1,j=10;i 4);运行结果:01010119(王勇超)#include stdio.hvoid main()int i=7,j;whil
17、e(i 2)j=i%2;printf(%d,j);i-;printf(%d,i);运行结果:10101220.(王勇超)#include void main()int i,j,t=0;for(i=3;i0;i-)for(j=0;j4;j+)t+=j;printf(t=%d,t);运行结果:t=18第六章第六章 函数函数共共 4040 道题道题1.(王伟)#include long fun(int x,int n);int main()int x=3,n=3;long p;p=fun(x,n);printf(p=%ldn,p);return 0;long fun(int x,int n)int
18、i;long p=1;for(i=0;in;i+)p*=x;return p;运行结果:p=272.(王伟)#include int isDigit(char ch);int main()char ch;while(ch=getchar()!=n)if(isDigit(ch)putchar(ch);printf(n);return 0;int isDigit(char ch)if(ch=0&ch=9)return 1;elsereturn 0;输入:Abc1d23eF45g运行结果:123453.(王伟)#include void odddivisor(int n);int main()int
19、 n;scanf(%d,&n);odddivisor(n);return 0;void odddivisor(int n)int i;for(i=3;i=n/2;i=i+2)if(n%i=0)printf(%5d,i);printf(n);输入:15运行结果:354.(王伟)#include void print();int a=5;int main()int a=1,b=2;a=a+b;print();printf(%d%dn,a,b);return 0;void print()int b=3;printf(%d%dn,a,b);运行结果:5 33 25.(王伟)#include int f
20、un1(int x);void fun2(int x);int main()int x=1;x=fun1(x);printf(%dn,x);return 0;int fun1(int x)x+;fun2(x);return x;void fun2(int x)x+;运行结果:26.(王伟)#include int fun1(int a,int b,int c);int main()int a=11,b=21,c=31;fun1(a,b,c);printf(%d%d%dn,a,b,c);return 0;int fun1(int a,int b,int c)a=a+10;b=b+10;c=c+1
21、0;return c;运行结果:11 21 317.(王伟)#includevoid fun(int x);int main()fun(7);printf(n);return 0;void fun(int x)if(x/21)fun(x/2);printf(%5d,x);运行结果:378.(王伟)#include void fun(int a);int main()int i,a5=1,2,3;fun(a);for(i=0;i5;i+)printf(%5d,ai);printf(n);return 0;void fun(int a)int i;for(i=0;i5;i+)ai+=5;运行结果:
22、678559.(于蕾)#include void fun(int k);void main()int w=5;fun(w);printf(n);void fun(int k)if(k0)fun(k-1);printf(%d,k);运行结果:01234510.(于蕾)#includevoid f1(void);int a=1;void main()int a=2;f1();int a=3;printf(a2=%dn,a);printf(a3=%dn,a);void f1(void)printf(a1=%dn,a);运行结果:a1=1a2=3a3=211.(于蕾)#includevoid f(in
23、t a,int b,int*c)a=20;b=10;*c=a+b;void main()int a=10,b=20,c=30,d=40;f(a,b,&c);printf(%d,%d,%dn,a,b,c);运行结果:10,20,3012.(于蕾)#includevoid swap(int a,int b);void main()int a=2,b=3;printf(a=%d,b=%dn,a,b);swap(a,b);printf(a=%d,b=%dn,a,b);void swap(int a,int b)int c;c=a;a=b;b=c;运行结果:a=2,b=3a=2,b=313.(于蕾)#i
24、nclude void fun(int a,int b,int c);void main()int x=10,y=20,z=30;fun(x,y,z);printf(%d,%d,%dn,x,y,z);void fun(int a,int b,int c)a=456;b=567;c=678;运行结果:10,20,3014.(于蕾)#include float f(int n)int i;float s=0.0;for(i=1;in;i+)s=s+(float)1.0/i;return s;void main()int i;float a=0.0;for(i=1;i3;i+)a=a+f(i);pr
25、intf(a=%.4fn,a);运行结果:a=1.000015.(于蕾)#include int f(int a);void main()int a=2,i;for(i=0;i3;i+)printf(%d,f(i);int f(int a)int b=0,c=3;b+;c+;return(a+b+c);运行结果:56716.(于蕾)#includeint fun();void main()int i,x;for(i=0;i=2;i+)x=fun();printf(%dn,x);int fun()int x=3;x+;return x;运行结果:417.(王锋)#include float ad
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C语言程序设计 语言程序设计 阅读 程序 结果 试题 汇总 2022
限制150内