版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、閱讀程序?qū)懡Y(jié)果試題第四章 選擇結(jié)構(gòu) (共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 );運(yùn)行結(jié)果: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);運(yùn)行結(jié)果:a=1,b=33. (于蕾)#include <stdio.h>void main( ) char ch1 = 'e' if(ch1 >= 'a') ch1+; else ch1+=32; printf("ch1 = %cn", ch1);運(yùn)行結(jié)果: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、 );運(yùn)行結(jié)果: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<回車>運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: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ùn)行結(jié)果: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;運(yùn)行結(jié)果: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"); 運(yùn)行結(jié)果:abc10 (王鋒)#include <stdio.h>void main()int i=0,a=2;if(i=0)printf(“*”);elseprintf(“$”);pr
8、intf(“*”);運(yùn)行結(jié)果:*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); 運(yùn)行結(jié)果: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;運(yùn)行結(jié)果:*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;運(yùn)行結(jié)果:*&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;運(yùn)行結(jié)果: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;運(yùn)行結(jié)果:*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<回車>運(yùn)行結(jié)果: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<回車>運(yùn)行結(jié)果: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);運(yùn)行結(jié)果: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");運(yùn)行結(jié)果: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 );運(yùn)行結(jié)果:8,1第五章 循環(huán)結(jié)構(gòu) 共20道題1. (于蕾)#include <stdio.h>void main() int number , digit; number = 1234; while ( number != 0 ) digit = number%10 ;printf( "%d" , digit ) ;number = number / 10 ;運(yùn)行結(jié)果:43212. (于蕾)#include <stdio.h>#define n 5void main( )int i; for(
16、i=1;i<n;i+) printf("%dn",i*i);運(yùn)行結(jié)果: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);運(yùn)行結(jié)果:i=6,s=94. (于蕾)#include <stdio.h>void main()int counter=1; while(counter <= 5) printf("%d
17、 n", counter ); counter+;運(yùn)行結(jié)果: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<回車>運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: * * *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;運(yùn)行結(jié)果:#
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;運(yùn)行結(jié)果: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<回車>運(yùn)行結(jié)果: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");運(yùn)行結(jié)果:*!*!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);運(yùn)行結(jié)果: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<回車>運(yùn)行
22、結(jié)果: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; 運(yùn)行結(jié)果: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<回車>運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: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);運(yùn)行結(jié)果:8,1218. 王勇超)#include "stdio.h"void main() int i=10,j; do j = i%2;printf( "%d",j );i-; while ( i> 4 ); 運(yùn)行結(jié)果: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 ); 運(yùn)行結(jié)果: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);運(yùn)行結(jié)果:t=18第六章 函數(shù) 共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;運(yùn)行結(jié)果: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<回車>運(yùn)行結(jié)果: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<回車>運(yùn)行結(jié)果: 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);運(yùn)行結(jié)果: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+;運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: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);運(yùn)行結(jié)果: 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;運(yùn)行結(jié)果: 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 ) ;運(yùn)行結(jié)果: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);運(yùn)行結(jié)果: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);運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: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);運(yùn)行結(jié)果: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、運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: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); 運(yùn)行結(jié)果: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);運(yùn)行結(jié)果: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);運(yùn)行結(jié)果:-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);運(yùn)行結(jié)果: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);運(yùn)行結(jié)果: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);運(yùn)行結(jié)果: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();運(yùn)行結(jié)果: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; 運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: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);運(yùn)行結(jié)果: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;運(yùn)行結(jié)果:(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;運(yùn)行結(jié)果: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;運(yùn)行結(jié)果: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");運(yùn)行結(jié)果: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、運(yùn)行結(jié)果: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);運(yùn)行結(jié)果: 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);運(yùn)行結(jié)果: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);運(yùn)行結(jié)果:c=136. (王勇超)# inc
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度工業(yè)廠房交易全程服務(wù)合同4篇
- 2024音樂(lè)制作方與影視制作公司版權(quán)許可合同
- 二零二五年度交通樞紐害蟲防治與消毒作業(yè)合同3篇
- 專業(yè)水電安裝及消防系統(tǒng)承包合同2024年版版B版
- 2025年度12年首次智慧旅游項(xiàng)目合作協(xié)議3篇
- 2025年度叉車租賃合同范本(叉車租賃與維護(hù))4篇
- 2025年度智慧城市基礎(chǔ)設(shè)施場(chǎng)地平整與物聯(lián)網(wǎng)協(xié)議4篇
- 2025年度奶牛養(yǎng)殖牛場(chǎng)租賃合同范本3篇
- 2025年廠房租賃合同風(fēng)險(xiǎn)評(píng)估與管理規(guī)范4篇
- 2024年04月廣西桂林銀行南寧分行社會(huì)招考筆試歷年參考題庫(kù)附帶答案詳解
- 聚焦任務(wù)的學(xué)習(xí)設(shè)計(jì)作業(yè)改革新視角
- 足球訓(xùn)練基地管理制度
- 太平洋藍(lán)鯨計(jì)劃制度和基本法
- (承諾書)安防監(jiān)控售后服務(wù)承諾書范文
- 高低溫交變濕熱試驗(yàn)檢測(cè)報(bào)告
- 蘇教版四年級(jí)數(shù)學(xué)下冊(cè)《全冊(cè)》完整課件ppt
- 《高一地理必修一全套課件》
- 新點(diǎn)軟件算量基礎(chǔ)知識(shí)內(nèi)部培訓(xùn)講義
- 幼兒園學(xué)前-《拍蚊子》教學(xué)課件設(shè)計(jì)
- 移動(dòng)商務(wù)內(nèi)容運(yùn)營(yíng)(吳洪貴)任務(wù)三 APP的品牌建立與價(jià)值提供
- 北師大版三年級(jí)數(shù)學(xué)上冊(cè)《總復(fù)習(xí)》教案及教學(xué)反思
評(píng)論
0/150
提交評(píng)論