版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、阅读程序写结果试题第四章 选择结构 (共20道题)1. (于蕾)#include <stdio.h>void main( ) int x,y,t;x=7;y=9;if(x<y) t=x;x=y;y=t;printf("%d,%dn" , x,y );运行结果:9,72. (于蕾)#include <stdio.h>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
2、",a,b);运行结果:a=1,b=33. (于蕾)#include <stdio.h>void main( ) char ch1 = 'E' if(ch1 >= 'A') ch1+; else ch1+=32; printf("ch1 = %cn", ch1);运行结果:ch1= F 4. (于蕾)#include <stdio.h>void main( ) int x,y,t;x=5;y=3;if(x>y) t=x;x=y;y=t;printf("%d,%dn" , x,y
3、 );运行结果:3,55. (王伟)#include <stdio.h>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(c<m)m=c;printf("m=%dn",m);return 0;输入:21 22 23<回车>运行结果:m=216. (王伟)#include <stdio.h>int main()ch
4、ar ch1='a',ch2='B',ch3='E'if(ch1>ch2)if(ch2>ch3)ch3+;else-ch3;printf("ch3=%cn",ch3);return 0;运行结果:ch3=D7. (王伟)#include <stdio.h>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
5、+1;printf("y=%fn",y);break;case 2: y=3*x*x+2;printf("y=%fn",y);break;default:printf("No definition.n"); return 0;输入:15.3<回车>运行结果:y=31.6000008. (王伟)#include <stdio.h>int main()char ch1='A',ch2='B'switch(ch1)case 'A':switch(ch2)case
6、9;B': printf("Good!n");break;case 'A': printf("Better!n");break;case 'B': printf("Best!n"); break;return 0;运行结果:Good!Best!9 (王锋)#include <stdio.h>void main() float score;score = 100;if (score<60) printf("En"); else switch( ( int )
7、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 <stdio.h>void main()int i=0,a=2;if(i=0)printf(“*”);elseprintf(“$”);pr
8、intf(“*”);运行结果:*11. (王锋)#include<stdio.h> 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. (王锋)#include<stdio.h>void main()int a=1,b=0;switch(a)case 1: switch (b)case 0: printf(“*0*”); break; case 1:printf(“*1*”);break;ca
9、se 2: printf(“*2*”);break;运行结果:*0*2*13. (宋昕)#include<stdio.h>int main( ) int a=2,b=7,c=5; switch (a>0) case 1: switch (b<0) case 1: printf(""); break ; case 2: printf("!"); break ; case 0: switch (c=5) case 1: printf("*") ; break ; default : printf("#&q
10、uot;) ; break ; default : printf("&"); printf("n"); return 0;运行结果:*&14. (宋昕)#include<stdio.h>int 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. (宋昕)#include<stdio.h>int main()
11、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 <stdio.h>int main() int x, y; scanf("%d",&x); y = x>12 ? x + 10 : x - 12; printf("%dn", y); return
12、0;输入:12<回车>运行结果:017. (宋昕)#include <stdio.h>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;
13、 printf("%.1f", r); return 0;输入:3.5<回车>运行结果:0.618. (王勇超)#include "stdio.h"void main( ) int a=7; if(a>9 | a<10) a=a/3; else a=a%3; printf("a=%d", a);运行结果:a=219. (王勇超)#include<stdio.h>void main() int a=20; switch(a%3) case 0: printf("0"); case
14、1: printf("1"); case 2: printf("2"); default: printf("3"); printf("4");运行结果:23420. (王勇超)#include <stdio.h>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(
15、"%d,%dn", a+, -c );运行结果:8,1第五章 循环结构 共20道题1. (于蕾)#include <stdio.h>void main() int number , digit; number = 1234; while ( number != 0 ) digit = number%10 ;printf( "%d" , digit ) ;number = number / 10 ;运行结果:43212. (于蕾)#include <stdio.h>#define N 5void main( )int i; for(
16、i=1;i<N;i+) printf("%dn",i*i);运行结果:149163. (于蕾)#include<stdio.h>void 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 <stdio.h>void main()int counter=1; while(counter <= 5) printf("%d
17、 n", counter ); counter+;运行结果:123455 (王伟)#include<stdio.h>int main()int i,sum,m,a;sum=0;m=5;for(i=0;i<=3;i+)scanf("%d",&a); if(a>m)sum+=a;printf("sum=%dn",sum);return 0;输入:2 10 8 3<回车>运行结果:sum=186. (王伟)#include<stdio.h>int main()int i,j,k;for(i=1;
18、i<=4;i+)for (j=1;j<5-i;j+)printf(" ");for(k=1;k<=i;k+)printf("*");printf("n");return 0;运行结果: * * *7. (王伟)#include <stdio.h>int main()int i,j;i=1;while(i<5)for(j=1;j<2*i+1;j+)printf("%c",'#');printf("n");i+;return 0;运行结果:#
19、8. (王伟)#include <stdio.h>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 <stdio.h>void main() int sum=0,n; scanf("%d",&n); while(n<=5) sum+=n; n+;printf("sum=%d",s
20、um);输入:1<回车>运行结果:sum=1510 (王锋)#include <stdio.h>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 <stdio.h>void main()int a,b;for(a=1,b=1;a<=100;a+)if(b>20)
21、 break;if(b%4=1)b=b+4;continue;b=b-5;printf("a=%dn",a);运行结果:a=612 (王锋)#include <stdio.h>void main( )char k; int i; for(i=1;i<3;i+) scanf("%c",&k); switch(k) case '0': printf("anothern");case '1': printf("numbern");输入:01<回车>运行
22、结果:anothernumbernumber13. (宋昕)#include <stdio.h>int main() int i, s = 0; for(i = 1; i < 10; i+) s += i * i; if(s > 10) break; printf("i=%d, s=%dn", i, s);return 0; 运行结果:i=3, s=14 14. (宋昕)#include <stdio.h>void main()char ch;while(ch=getchar()!='n') if (ch>='
23、;A'&&ch<='Z')ch=ch+32;else if (ch>='a'&&ch<='z')ch=ch-32;printf("%c",ch);输入:ABCdef<回车>运行结果:abcDEF15. (宋昕)#include <stdio.h>int main () int a, b; for (a = 1, b = 1 ; a <= 100 ; a+) if (b >= 9) break; if (b % 3 = 1) b +=
24、3 ; continue ; b -= 5; printf("%d,%dn", a, b); return 0;运行结果:4,1016. (宋昕)#include<stdio.h>int 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.h"void main( ) int i,j,t; for
25、(i=1,j=10;i<3;i+,j-) t=i+j; t+;printf("%d,%d",j,t);运行结果:8,1218. 王勇超)#include "stdio.h"void main() int i=10,j; do j = i%2;printf( "%d",j );i-; while ( i> 4 ); 运行结果:01010119 (王勇超)#include "stdio.h"void main() int i=7,j; while ( i> 2) j = i%2;printf( &qu
26、ot;%d",j );i-; printf( "%d",i ); 运行结果:10101220. (王勇超)#include <stdio.h>void main()int i,j,t=0;for(i=3;i>0;i-)for(j=0;j<4;j+)t+=j;printf("t=%d",t);运行结果:t=18第六章 函数 共40道题1. (王伟)#include <stdio.h>long fun(int x,int n);int main()int x=3,n=3;long p;p=fun(x,n);pri
27、ntf("p=%ldn",p);return 0;long fun(int x,int n)int i;long p=1; for(i=0;i<n;i+)p*=x; return p;运行结果:p=272. (王伟)#include <stdio.h>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&g
28、t;='0' && ch<='9')return 1;elsereturn 0;输入:Abc1d23eF45g<回车>运行结果:123453. (王伟)#include <stdio.h>void odddivisor(int n);int main()int 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("%5
29、d",i);printf("n");输入:15<回车>运行结果: 3 54. (王伟)#include <stdio.h> 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 <stdio.h> int fun1(int x);void
30、 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 <stdio.h> 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
31、 b,int c)a=a+10;b=b+10;c=c+10;return c;运行结果:11 21 317. (王伟)#include<stdio.h>void fun(int x);int main()fun(7);printf("n");return 0;void fun(int x)if(x/2>1)fun(x/2);printf("%5d",x);运行结果: 3 78. (王伟)#include <stdio.h> void fun(int a);int main()int i,a5=1,2,3;fun(a);for
32、(i=0;i<5;i+)printf("%5d",ai);printf("n");return 0;void fun(int a)int i;for(i=0;i<5;i+)ai+=5;运行结果: 6 7 8 5 59.(于蕾)#include <stdio.h>void fun ( int k ) ;void main ( ) int w = 5 ; fun ( w ) ; printf ( "n" ) ;void fun ( int k ) if ( k>0 ) fun ( k-1 ) ; printf
33、 ( "%d" , k ) ;运行结果:01234510. (于蕾)#include<stdio.h>void 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. (于蕾)#include<stdio.h>void f(int a, int b, int *c)a=
34、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. (于蕾)#include<stdio.h>void 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
35、 c;c=a;a=b;b=c;运行结果:a=2,b=3a=2,b=313. (于蕾)#include <stdio.h>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 <stdio.h>float f(int n) int i;float s=0.0; for(
36、i=1;i<n;i+) s=s+(float)1.0/i; return s;void main()int i;float a=0.0; for(i=1;i<3;i+) a=a+f(i); printf("a=%.4fn", a);运行结果:a=1.000015. (于蕾)#include <stdio.h>int f(int a);void main()int a=2,i;for(i=0;i<3;i+)printf("%d",f(i);int f(int a)int b=0,c=3;b+;c+;return(a+b+c);
37、运行结果:56716. (于蕾)#include<stdio.h>int 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 <stdio.h>float add(float x,float y); void main( ) float a,b,c; a=1.0; b=2.0; c=add(a,b); printf("%fn",c);f
38、loat add(float x,float y)float z;z=x+y;return(z); 运行结果:3.00000018. (王锋)#include<stdio.h>void fun(int x, int cp, int dp) cp=x+; dp=+x; void main(void) int a,c=80, d=-20;a=30; fun(a,c,d);printf("%d,%dn", c,d);运行结果:80,-2019. (王锋)#include <stdio.h>int f(int a,int b);void main()int
39、i=2,p;p=f(i,i+1);printf("%dn",p);int f(int a,int b)int c;if(a>b)c=1;else if (a=b)c=0;else c=-1;return (c);运行结果:-120. (王锋)#include <stdio.h>int fun(int n)if(n= =1) return 1;else return fun(n-1)+3;void main()int i,j=0;for(i=1;i<4;i+)j=j+fun(i);printf("j=%dn",j);运行结果:j=1
40、221. (王锋)#include <stdio.h>void f(int x,int y)int t;if(x<y)t=x;x=y;y=t;void main()int a=4,b=3,c=5; f(a,b); f(a,c); f(b,c);printf("%d,%d,%d",a,b,c);运行结果:4,3,522. (王锋)#include<stdio.h>int age(int n)int c; if(n=1) c=10;else c=age(n-1)+2;return(c);void main()printf("%d"
41、;,age(5);运行结果:1823. (王锋)#include <stdio.h>void hello_world(void)printf("Hello, world!n");void three_hellos(void)int counter;for (counter =1;counter <= 3;counter+)hello_world();void main(void)three_hellos();运行结果:Hello, world!Hello, world!Hello, world!24. (王锋)#include <stdio.h>
42、;int f(int a,int b); void main() int x,i=1,k=3; x=f(i,k); printf("x=%d n",x); int f(int a,int b) int M=0; while(b!=0) M=M+a; b-; return M; 运行结果:x=3;25. (宋昕)#include<stdio.h>f(int b ,int m,int n) int i,s = 0; for(i = m;i < n;i+) s += bi; return s; int main() int x,a = 1,2,3,4,5,6,7
43、,8,9, *p = a; x = f(p,3,7); printf("x=%dn",x); return 0;运行结果:x=2226. (宋昕)#include <stdio.h>void fun(int i, int j) int x = 7; printf("i = %d; j = %d; x = %dn", i, j, x);int main() int i = 2, x = 5, j = 7; fun(j, 6); printf("i = %d; j = %d; x = %dn", i, j, x); retur
44、n 0;运行结果:i = 7; j = 6; x = 7i = 2; j = 7; x = 527. (宋昕)#include <stdio.h>void f(int a) int i=0; while(ai<=10) printf("%d",ai); i+; int main() int a=1,7,17,9,11,34; f(a+1);运行结果:728. (宋昕)#include <stdio.h>void add(int x, int y, int z) z = x + y; x = x * x; y = y * y; printf(&q
45、uot;(2) x = %d y = %d z = %dn", x, y, z);int main() int x = 2, y = 3, z = 0; printf("(1) x = %d y = %d z = %dn", x, y, z); add(x, y, z); printf("(3) x = %d y = %d z = %dn", x, y, z); return 0;运行结果:(1) x = 2 y = 3 z = 0(2) x = 4 y = 9 z = 5(3) x = 2 y = 3 z = 029. (宋昕)#includ
46、e <stdio.h>int x1 = 30, x2 = 40;void sub(int x, int y) x1 = x; x = y; y = x1;int main() int x3 = 10, x4 = 20; sub(x3, x4); sub(x2, x1); printf(" %d, %d, %d, %dn", x3, x4, x1, x2); return 0;运行结果:10, 20, 40, 4030. (宋昕)#include<stdio.h>int x;void cube() x = x * x * x;int main() x
47、= 5; cube(); printf(" %dn", x); return 0;运行结果:12531. (宋昕)#include <stdio.h>invert(int *s, int i, int j) int t; if(i < j) invert(s, i + 1,j - 1); t = *(s + i); *(s + i) = *(s + j); *(s + j) = t; void main( ) int a6 = 10, 6, 23, -90, 0, 3, i; invert(a, 0, 5); for(i = 0; i < 6; i+
48、) printf("%d, ", ai); printf("n");运行结果:3,0,-90,23,6,1032. (宋昕)int func(int a3) int i,j,sum=0; for(i=0;i<3;i+) for(j=0;j<3;j+) aij=i+j; if(i=j) sum = sum+aij; return sum;int main() int a33=1,3,5,7,9,11,13,15,17; int sum; sum=func(a); printf("sum=%d",sum); return 0;
49、运行结果:sum=633. (王勇超)# include <stdio.h> int i=10;void fun();void main( ) int i; for(i=2; i>0; i-) fun( );void fun() i*=2; printf("i=%dn", i);运行结果: i=20i=4034(王勇超)#include <stdio.h>int fun(int n) if(n<=1) return 1;else return fun(n-1)*n;void main() int i,j=0; for(i=1;i<=3;i+) j+=fun(i);printf("j=%dn",j);运行结果:j=935. (王勇超)#include <stdio.h>int funa(int a, int b) int t; if (a > b) t = a/b; else t = a%22; return t;void main()int a=33, b=22,c;c=funa(a,b);printf("c=%dn", c);运行结果:c=136. (王勇超)# inc
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 新质生产力驱动户外运动产业高质量发展:供需逻辑、效应机制及实现路径
- 医院信息化系统报价方案
- 塑料橡胶材料专业超声波塑料焊接深圳市恒波超声设备有限公
- 纯碱的性质课件
- 长治2024年山西长治文化艺术学校(豫剧团)招聘豫剧演员专业技术人员笔试历年典型考点(频考版试卷)附带答案详解版
- 零售业智慧物流网络构建考核试卷
- 零售业数据分析工具考核试卷
- 铁路机车车辆配件售后服务体系建设考核试卷
- 胃痛治疗策略优化-洞察分析
- 文学风格自适应生成-洞察分析
- 小学高年级课后服务 scratch3.0编程教学设计 一阶第27课 植物大战僵尸-僵尸来袭教学设计
- 2024年人民日报社招聘应届高校毕业生85人笔试高频难、易错点500题模拟试题附带答案详解
- 中西医结合科工作制度
- 沈鼓集团招聘笔试题库2024
- 高中人教版必修一全册历史期末总复习重要知识点归纳
- 2024年网络安全知识竞赛考试题库500题(含答案)
- 南平武夷高新技术产业控股集团有限公司招聘笔试题库2024
- 《2024年 基于Python的电影弹幕数据分析》范文
- 三支一扶协议书模板
- 施工现场临时用电安全监理检查表
- 2024年全国职业院校技能大赛高职组(护理技能赛项)备赛试题库(含答案)
评论
0/150
提交评论