您的当前位置:首页正文

《C语言程序设计》阅读程序写结果试题汇总情况

2020-11-08 来源:汇智旅游网
标准实用

阅读程序写结果试题

第四章 选择结构 (共20道题)

1. (于蕾)

#include void main( ) {

int x,y,t; x=7;y=9; if(x{ t=x;x=y;y=t;}

printf(\"%d,%d\\n\" , x,y ); }

运行结果: 9,7

2. (于蕾)

#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=%d\\n\}

运行结果: a=1,b=3

3. (于蕾)

#include void main( ) {

char ch1 = 'E'; if(ch1 >= 'A')

文案大全

标准实用

ch1++; else

ch1+=32;

printf(\"ch1 = %c\\n\}

运行结果: ch1= F

4. (于蕾)

#include void main( ) {

int x,y,t; x=5;y=3; if(x>y)

{ t=x;x=y;y=t;}

printf(\"%d,%d\\n\" , x,y ); }

运行结果: 3,5

5. (王伟)

#include int main() {

int a,b,c,m;

printf(\"Enter three integers:\"); scanf(\"%d%d%d\ if(a<=b) m=a; else m=b; if(cprintf(\"m=%d\\n\ return 0; }

输入:21 22 23<回车>

运行结果: m=21

文案大全

标准实用

6. (王伟)

#include int main() {

char ch1='a',ch2='B',ch3='E'; if(ch1>ch2) if(ch2>ch3) ch3++; else

--ch3;

printf(\"ch3=%c\\n\ return 0; }

运行结果: ch3=D

7. (王伟)

#include int main() {

float x,y;

scanf(\"%f\ switch((int)x/10) {

case 0: y=1.0;

printf(\"y=%f\\n\ case 1: y=2*x+1;

printf(\"y=%f\\n\ case 2: y=3*x*x+2;

printf(\"y=%f\\n\ default:

printf(\"No definition.\\n\"); }

return 0; }

输入:15.3<回车>

运行结果: y=31.600000

文案大全

标准实用

8. (王伟)

#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 (score<60) printf(\"E\\n\"); else

switch( ( int ) score / 10 )

{ case 10: case 9: printf(\"A\\n\"); case 8: printf(\"B\\n\");

case 7: printf(\"C\\n\"); break; case 6: printf(\"D\\n\"); break; default: printf(\"Error\\n\"); } }

运行结果:

文案大全

标准实用

A B C

10. (王锋) #include void main() {

int i=0,a=2; if(i==0)

printf(“**”); else

printf(“$$”); 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=35

12. (王锋) #include void main() {

int a=1,b=0; switch(a)

文案大全

q=q+p;

printf(“q=%d\\n”,q);

标准实用

{

case 1: switch (b) {

case 0: printf(“**0**”); break;

case 1:printf(“**1**”);break;

}

case 2: printf(“**2**”);break; } }

运行结果: **0****2**

13. (宋昕)

#include 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(\"#\") ; break ; }

default : printf(\"&\"); }

printf(\"\\n\"); return 0; }

运行结果: *&

14. (宋昕)

#include 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=%d\\n\ return 0; }

运行结果: d=20

15. (宋昕)

#include int 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\

y = x>12 ? x + 10 : x - 12; printf(\"%d\\n\ return 0; }

输入:12<回车>

运行结果: 0

17. (宋昕)

#include int main() {

float x, y; char op; double r;

文案大全

标准实用

scanf(\"%c%f%f\ switch(op)

{ case '+': r = x + y; break; case '-': r = x - y; break; case '*': r = x * y; break; case '/': r = x / y; break; }

printf(\"%.1f\ return 0; }

输入:3.5<回车>

运行结果: 0.6

18. (王勇超) #include \"stdio.h\" void main( ) {

int a=7;

if(a>9 || a<10) a=a/3; else

a=a%3;

printf(\"a=%d\}

运行结果: a=2

19. (王勇超) #include void main() {

int a=20; switch(a%3) {

case 0: printf(\"0\"); case 1: printf(\"1\"); case 2: printf(\"2\"); default: printf(\"3\"); }

printf(\"4\");

文案大全

标准实用

}

运行结果: 234

20. (王勇超) #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,%d\\n\}

运行结果: 8,1

第五章 循环结构 共20道题

1. (于蕾)

#include void main() {

int number , digit; number = 1234;

while ( number != 0 ) {

digit = number%10 ;

printf( \"%d\" , digit ) ; number = number / 10 ; } }

运行结果: 4321

2. (于蕾)

#include #define N 5 void main( ) {

文案大全

标准实用

int i;

for(i=1;iprintf(\"%d\\n\}

运行结果: 1 4 9 16

3. (于蕾)

#include 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=%d\\n\}

运行结果: i=6,s=9

4. (于蕾)

#include void main() {

int counter=1;

while(counter <= 5) {

printf(\"%d \\n\ counter++;

} }

运行结果: 1 2 3 4

文案大全

标准实用

5

5. (王伟)

#include int main() {

int i,sum,m,a; sum=0; m=5;

for(i=0;i<=3;i++) {

scanf(\"%d\ if(a>m) sum+=a; }

printf(\"sum=%d\\n\ return 0; }

输入:2 10 8 3<回车>

运行结果: sum=18

6. (王伟)

#include int main() {

int i,j,k;

for(i=1;i<=4;i++) {

for (j=1;j<5-i;j++) printf(\" \"); for(k=1;k<=i;k++) printf(\"*\"); printf(\"\\n\"); }

return 0; }

运行结果: * ** *** ****

文案大全

标准实用

7. (王伟)

#include 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; }

运行结果: ## #### ###### ########

8. (王伟)

#include int main() {

int i=10,m=0,n=0; do {

if(i%2!=0) m=m+i; else

n=n+i; i--;

}while(i>=0);

printf(\"m=%d,n=%d\\n\ return 0; }

运行结果: m=25,n=30

9. (王锋)

#include

文案大全

标准实用

void main() {

int sum=0,n; scanf(\"%d\ while(n<=5) {

sum+=n; n++; }

printf(\"sum=%d\}

输入:1<回车>

运行结果: sum=15

10. (王锋)

#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;a<=100;a++) {

if(b>20) break;

文案大全

标准实用

if(b%4==1) {

b=b+4; continue; } b=b-5; }

printf(\"a=%d\\n\}

运行结果: a=6

12. (王锋)

#include void main( ) {

char k; int i;

for(i=1;i<3;i++) {

scanf(\"%c\ switch(k) {

case '0': printf(\"another\\n\"); case '1': printf(\"number\\n\"); } } }

输入:01<回车>

运行结果: another number number

13. (宋昕)

#include int main() {

int i, s = 0;

for(i = 1; i < 10; i++) {

s += i * i;

文案大全

标准实用

if(s > 10) break; }

printf(\"i=%d, s=%d\\n\ return 0; }

运行结果: i=3, s=14

14. (宋昕)

#include void main() {

char ch;

while((ch=getchar())!='\\n') {

if (ch>='A'&&ch<='Z') ch=ch+32;

else if (ch>='a'&&ch<='z') ch=ch-32; printf(\"%c\ } }

输入:ABCdef<回车>

运行结果: abcDEF

15. (宋昕)

#include int main () {

int a, b;

for (a = 1, b = 1 ; a <= 100 ; a++) {

if (b >= 9) break; if (b % 3 == 1) {

b += 3 ; continue ; }

b -= 5; }

printf(\"%d,%d\\n\

文案大全

标准实用

return 0; }

运行结果: 4,10

16. (宋昕)

#include int main () {

int i = 0,j = 0; while (i < 10) i++; while (j++ < 10) ;

printf(\"i=%d,j=%d\\n\ return 0; }

运行结果: i=10,j=11

17. (王勇超) #include \"stdio.h\" void main( ) {

int i,j,t;

for(i=1,j=10;i<3;i++,j--) t=i+j; t++;

printf(\"%d,%d\}

运行结果: 8,12

18. 王勇超)

#include \"stdio.h\" void main() {

int i=10,j; do {

j = i%2;

printf( \"%d\ i--;

文案大全

标准实用

} while ( i> 4 ); }

运行结果: 010101

19. (王勇超) #include \"stdio.h\" void main() {

int i=7,j; while ( i> 2) {

j = i%2;

printf( \"%d\ i--; }

printf( \"%d\ }

运行结果: 101012

20. (王勇超) #include 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=18

第六章 函数 共40道题

1. (王伟)

#include long fun(int x,int n); int main()

文案大全

标准实用

{

int x=3,n=3; long p; p=fun(x,n);

printf(\"p=%ld\\n\ return 0; }

long fun(int x,int n) {

int i; long p=1;

for(i=0;i运行结果: p=27

2. (王伟)

#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; else

return 0; }

输入:Abc1d23eF45g<回车>

运行结果:12345

文案大全

标准实用

3. (王伟)

#include

void odddivisor(int n); int main() {

int n;

scanf(\"%d\ 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\ printf(\"\\n\"); }

输入:15<回车>

运行结果: 3 5

4. (王伟)

#include void print(); int a=5; int main() {

int a=1,b=2; a=a+b; print();

printf(\"%d %d\\n\ return 0; }

void print() {

int b=3;

printf(\"%d %d\\n\}

运行结果: 5 3 3 2

文案大全

标准实用

5. (王伟)

#include int fun1(int x); void fun2(int x); int main() {

int x=1; x=fun1(x);

printf(\"%d\\n\ return 0; }

int fun1(int x) {

x++; fun2(x); return x; }

void fun2(int x) {

x++; }

运行结果: 2

6. (王伟)

#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 %d\\n\ return 0; }

int fun1(int a,int b,int c) {

a=a+10; b=b+10; c=c+10; return c; }

运行结果:

文案大全

标准实用

11 21 31

7. (王伟)

#include 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\}

运行结果: 3 7

8. (王伟)

#include void fun(int a[]); int main() {

int i,a[5]={1,2,3}; fun(a);

for(i=0;i<5;i++)

printf(\"%5d\ printf(\"\\n\"); return 0; }

void fun(int a[]) {

int i;

for(i=0;i<5;i++) a[i]+=5; }

运行结果:

6 7 8 5 5

9.(于蕾)

#include

文案大全

标准实用

void fun ( int k ) ; void main ( ) {

int w = 5 ; fun ( w ) ;

printf ( \"\\n\" ) ; }

void fun ( int k ) {

if ( k>0 )

fun ( k-1 ) ; printf ( \"%d\" , k ) ; }

运行结果: 012345

10. (于蕾)

#include void f1(void); int a=1; void main( ) {

int a=2; f1(); {

int a=3;

printf(\"a2=%d\\n\}

printf(\"a3=%d\\n\}

void f1(void) {

printf(\"a1=%d\\n\}

运行结果: a1=1 a2=3 a3=2

11. (于蕾)

文案大全

标准实用

#include

void f(int 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,%d\\n\}

运行结果: 10,20,30

12. (于蕾)

#include

void swap(int a,int b); void main() {

int a=2,b=3;

printf(\"a=%d,b=%d\\n\ swap(a,b);

printf(\"a=%d,b=%d\\n\}

void swap(int a,int b) {

int c; c=a; a=b; b=c; }

运行结果: a=2,b=3 a=2,b=3

13. (于蕾)

#include

void fun(int a,int b,int c); void main() {

int x=10,y=20,z=30;

文案大全

标准实用

fun(x,y,z);

printf(\"%d,%d,%d\\n\}

void fun(int a,int b,int c) {

a=456;b=567;c=678; }

运行结果: 10,20,30

14. (于蕾)

#include float f(int n) {

int i;float s=0.0; for(i=1;ivoid main() {

int i;float a=0.0; for(i=1;i<3;i++) a=a+f(i);

printf(\"a=%.4f\\n\}

运行结果: a=1.0000

15. (于蕾)

#include int f(int a); void main() {

int a=2,i;

for(i=0;i<3;i++)

printf(\"%d\

}

int f(int a) {

int b=0,c=3; b++;

文案大全

标准实用

c++;

return(a+b+c); }

运行结果: 567

16. (于蕾)

#include int fun(); void main() {

int i,x;

for(i=0;i<=2;i++) x=fun();

printf(\"%d\\n\ }

int fun() {

int x=3; x++;

return x; }

运行结果: 4

17. (王锋)

#include

float add(float x,float y); void main( ) {

float a,b,c; a=1.0; b=2.0;

c=add(a,b);

printf(\"%f\\n\}

float add(float x,float y) {

float z; z=x+y; return(z); }

文案大全

标准实用

运行结果: 3.000000

18. (王锋)

#include

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,%d\\n\}

运行结果: 80,-20

19. (王锋)

#include int f(int a,int b); void main() {

int i=2,p; p=f(i,i+1);

printf(\"%d\\n\}

int f(int a,int b) {

int c; if(a>b) c=1;

else if (a==b) c=0; else c=-1; return (c); }

运行结果:

文案大全

标准实用

-1

20. (王锋)

#include 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=%d\\n\}

运行结果:j=12

21. (王锋)

#include void f(int x,int y) {

int t; if(x{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\}

运行结果: 4,3,5

22. (王锋)

#include int age(int n) {

int c;

文案大全

标准实用

if(n==1)

c=10;

else

c=age(n-1)+2; return(c);

}

void main() {

printf(\"%d\}

运行结果: 18

23. (王锋)

#include 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 int f(int a,int b); void main() {

int x,i=1,k=3; x=f(i,k);

printf(\"x=%d \\n\

文案大全

标准实用

}

int f(int a,int b) {

int M=0; while(b!=0) {

M=M+a; b--; }

return M; }

运行结果: x=3;

25. (宋昕)

#include

f(int b[ ],int m,int n) {

int i,s = 0;

for(i = m;i < n;i++) s += b[i]; return s; }

int main() {

int x,a[ ] = {1,2,3,4,5,6,7,8,9}, *p = a; x = f(p,3,7);

printf(\"x=%d\\n\ return 0; }

运行结果: x=22

26. (宋昕)

#include void fun(int i, int j) {

int x = 7;

printf(\"i = %d; j = %d; x = %d\\n\}

int main() {

文案大全

标准实用

int i = 2, x = 5, j = 7; fun(j, 6);

printf(\"i = %d; j = %d; x = %d\\n\ return 0; }

运行结果:

i = 7; j = 6; x = 7 i = 2; j = 7; x = 5

27. (宋昕)

#include void f(int a[]) {

int i=0;

while(a[i]<=10)

{

printf(\"%d\ i++; } }

int main() {

int a[]={1,7,17,9,11,34}; f(a+1); }

运行结果: 7

28. (宋昕)

#include

void add(int x, int y, int z) {

z = x + y; x = x * x; y = y * y;

printf(\"(2) x = %d y = %d z = %d\\n\}

int main() {

int x = 2, y = 3, z = 0;

printf(\"(1) x = %d y = %d z = %d\\n\

文案大全

标准实用

add(x, y, z);

printf(\"(3) x = %d y = %d z = %d\\n\ return 0; }

运行结果:

(1) x = 2 y = 3 z = 0 (2) x = 4 y = 9 z = 5 (3) x = 2 y = 3 z = 0

29. (宋昕)

#include 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, %d\\n\ return 0; }

运行结果: 10, 20, 40, 40

30. (宋昕)

#include int x;

void cube() {

x = x * x * x; }

int main() {

x = 5; cube();

文案大全

标准实用

printf(\" %d\\n\ return 0; }

运行结果: 125

31. (宋昕)

#include

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 a[6] = {10, 6, 23, -90, 0, 3}, i; invert(a, 0, 5);

for(i = 0; i < 6; i++) printf(\"%d, \ printf(\"\\n\"); }

运行结果:

3,0,-90,23,6,10

32. (宋昕)

int func(int a[][3]) {

int i,j,sum=0; for(i=0;i<3;i++)

for(j=0;j<3;j++){ a[i][j]=i+j; if(i==j)

sum = sum+a[i][j]; }

return sum; }

int main()

文案大全

标准实用

{

int a[3][3]={1,3,5,7,9,11,13,15,17}; int sum; sum=func(a);

printf(\"sum=%d\ return 0; }

运行结果: sum=6

33. (王勇超)

# include int i=10; void fun(); void main( ) { int i;

for(i=2; i>0; i--) fun( ); }

void fun() {

i*=2;

printf(\"i=%d\\n\}

运行结果: i=20 i=40 34.(王勇超)

#include 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=%d\\n\}

运行结果: j=9

35. (王勇超) #include 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=%d\\n\}

运行结果: c=1

36. (王勇超)

# include void fun(int i); void main( ) { int i;

for(i=2; i>0; i--) fun(i); }

void fun(int i) {

i*=2;

printf(\"+%d+\}

运行结果:+4++2+

37. (王勇超)

文案大全

标准实用

# include void fun(int n); void main( ) {

int x=879; fun(x); }

void fun(int n) {

int a,b,c,t; a = n % 10;

b = (n/10) % 10; c = (n/100) % 10;

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\ }

运行结果:8

38.(王勇超)

#include int funa(int a, int b) {

int t; if (a > b) {

t = a; a = b; b = t; }

return t; }

void main() {

int a=33, b=22,c; c=funa(a,b);

printf(\"c=%d\\n\}

运行结果: c=33

文案大全

标准实用

39. (王勇超) #include int swap(int x, int y) {

int z; z=x%10; x=y%10; y=z; z=x;

return z; }

void main() {

int a=38, b=29,c; c=swap(a,b);

printf(\"%d%d\\n\}

运行结果: 389

40. (王勇超) #include void fun(int n) {

if(n==1)

printf(\"*\\n\"); else {

printf(\"-\"); fun(n-1); } }

void main() {

int i,j=0;

for(i=1;i<4;i++) fun(i);

printf(\"XiaoXin!\"); }

运行结果: *

文案大全

标准实用

-* --*

XiaoXin!

第七章 数组 共40道题

1. (王锋)

#include void main() {

int a[2][3]={{3,2,7},{4,8,6}}; int i,j,m=0; for(i=1;i<=1;i++) for(j=0;j<=i;j++) m=m+a[i][j]; printf(\"m=%d\}

运行结果: m=12

2. (王锋)

#include void main(void) {

int array[10] = {1, 2, 4, 5, 6, 0, 0, 0, 0, 0}, i;

printf(\"\\n\"); for (i=0; i<10; i++) printf(\"%3d \

printf(\"\\n\"); for (i=9; i>=2; i--)

array[i] = array[i-1];

array[2] = 3; for (i=0; i<10; i++)

printf(\"%3d \

printf(\"\\n\");

}

运行结果:

文案大全

标准实用

1 2 4 5 6 0 0 0 0 0 1 2 3 4 5 6 0 0 0 0

3. (王锋)

#include void main(void) { }

运行结果:CDG

4. (王锋) #include #include void main() { }

运行结果:

Hello Teachers,Students.

char a[30]=\"Hello \"; char b[10]=\"Students\"; char c[10]=\"Teachers\"; strcat(a,c);

printf(\"%s,%s.\\n\

char a[]=\"ABCDEFGH\char *p1,*p2; int k; p1=a; p2=b; for(k=0;k<=7;k++)

if (*(p1+k)==*(p2+k))

printf(\"%c\

printf(\"\\n\");

文案大全

标准实用

5.(王锋)

#include

void inv(int x[],int n); void main() {

int i, a[10]={3,7,9,11,0,6,7,5,4,2}; inv(a, 10);

printf(\"The array has been reverted.\\n\"); for(i=0;i<10;i++)

printf(\"%d,\ printf(\"\\n\"); }

void inv(int x[], int n) {

int t,i,j,m=(n-1)/2; for(i=0;i<=m;i++) {

j=n-1-i; t=x[i]; x[i]=x[j]; x[j]=t; } }

运行结果:

The array has been reverted. 2,4,5,7,6,0,11,9,7,3,

6. (王锋)

#include void main() {

float a[3][3]={1,2,3,4,5,6,7,8,9},sum=0; int i;

printf(\"please input rectangle element:\\n\"); for(i=0;i<3;i++) sum=sum+a[i][i];

printf(\"duijiaoxian he is %6.2f\}

运行结果:

please input rectangle element: duijiaoxian he is 15.00

7. (宋昕)

#include

文案大全

标准实用

int main() {

int i=1,n=3,j,k=3; int a[5]={1,4,5};

while(i<=n&&k>a[i]) i++; for(j=n-1;j>=i;j--) a[j+1] = a[j]; a[i] = k;

for(i=0;i<=n;i++)

printf(“%2d”,a[i]); return 0; }

运行结果: 1 3 4 5

8. (王锋)

#include void main() {

int a[10]={0,1,2,3,4,5,6,7,8,9}, b[10],i,sum=0; for(i=1;i<10;i++) {

b[i]=a[i-1]+a[i]; sum=sum+b[i]; }

for(i=1;i<10;i++) if(i%3==0)

sum=sum+b[i]; printf(\"sum=%3d\}

运行结果: sum=114

9. (王勇超)

#include void main() {

int a[5]={2,6,1,3,4},n=5,i,j,t; for(i=0,j=1;ja[j]=a[i]; i++;

文案大全

标准实用

}

for(i=0;iprintf(\"%d\}

运行结果: 22121

10. (王勇超) #include

void funa(int x[],int n); void main() {

int i, a[5]={3,7,9,11,0}; funa(a, 5);

for(i=0;i<5;i++)

printf(“%d,”,a[i]); printf(“\\n”); }

void funa(int x[], int n) {

int t,i,j,m=(n-1)/2; for(i=0;i<=m;i++) {

j=n-1-i; t=x[i]; x[i]=x[j]; x[j]=t; } }

运行结果: 0,11,9,7,3,

11. (王勇超) #include void main() {

int a[5]={24,15,33,64,45},n=5,i,j,t; for(i=0;i0;i--)

printf(\"%d,\}

文案大全

标准实用

运行结果: 5,4,3,5,4,

12. (王勇超) #include void main() {

int a[5],i,j,t; for(i=4;i>=0;i--)

scanf(\"%d\ for(i=0;i<5;i++) a[i]=a[i]+10; for(i=0;i<5;i++)

printf(\"%d,\}

输入:42 31 24 15 16<回车>

运行结果: 26,25,34,41,52

13. (王勇超) #include main() {

char a[][5]={\"Zhong\ printf(\"%s\\n%s\\n\}

运行结果: ZhongGong Gong

14. (王勇超) #include void main() {

int a[3][3]={0,1,2,3,4,5,6,7,8},i,j,t; for(i=0;i<3;i++) for(j=0;j<3;j++)

a[i][j]+=a[i][0];

for(i=0;i<3;i++)

printf(\"%d,\}

运行结果: 0,10,20

文案大全

标准实用

15. (王勇超) #include void main() {

int a[3][3]={1,2,3,4,5,6,7,8,9},i,j; for(i=0;i<3;i++) for(j=0;j<3;j++)

a[i][j]+=a[i][2]; while(i>0) {

i--;

printf(\"%d,\ } }

运行结果: 18,11,4

16. (王勇超) #include void main() {

int i,j;

char a[10]={\"ABCDEFGHIJ\ for(i=0;i<10;i++) a[i]=a[i]+3;

printf(\"%c\\n\}

运行结果: J

17. (王伟)

#include int main() {

int i,a[10]={0,1,2,3,4,5,6,7}; for(i=1;i<9;i++)

a[i]=a[i-1]+a[i+1]; printf(\"%d%d\\n\ return 0; }

运行结果: 2027

文案大全

标准实用

18. (王伟)

#include int main() {

int i,a[]={1,2,3,4,5,6,7,8,9,10}; for(i=0;i<5;i++) a[i]=i+2; for(i=9;i>=0;i--) if(a[i]%3==0)

printf(\"%d\\n\ return 0; }

运行结果: 9 6 6 3

19. (王伟)

#include int main() {

int num=13,len=0,i=0,a[30]; do {

a[len]=num%2; num=num/2; len++; }while(num);

for(i=0;iprintf(\"%d\ printf(\"\\n\"); return 0; }

运行结果: 1101

20. (王伟)

#include int main() {

int a[5]={6,9,12,16};

文案大全

标准实用

}

int x,i=3;

scanf(\"%d\

while(i>=0 && xa[i+1]=a[i]; i--; }

a[i+1]=x;

for(i=0;i<5;i++)

printf(\"%5d\printf(\"\\n\"); return 0;

输入:10<回车>

运行结果:

6 9 10 12 16

21. (王伟)

#include int main() {

int a[3][3]={{2,3},{4,5,6},{7,8}}; int i=0,j=0,m; m=a[0][0];

for(i=0;i<3;i++) for(j=0;j<3;j++) if(a[i][j]运行结果: m=0

22. (王伟)

#include #include int main() {

int i;

char str[20]=\"abcdef\"; strcpy(str,\"opqrst\"); str[5]='\\0';

文案大全

标准实用

}

for(i=0;i运行结果: opqr

23. (王伟)

#include #include int main() {

char a[10]=\"AB\ int i=0; while(b[i]) {

a[i]=b[i]; i++; }

a[i]='\\0'; puts(b); return 0; }

运行结果: LMNP

24. (王伟)

#include #include int main() {

int i;

char str1[30]=\"abc\ for(i=1;i<3;i++)

strcat(str1,str2[i]); puts(str1); return 0; }

运行结果: abchiklm

文案大全

标准实用

25. (宋昕)

#include int main() {

int i;

char a[] = \"Time\

for(i = 0; a[i] != '\\0' && b[i] != '\\0'; i++){ if (a[i] == b[i])

if (a[i] >= 'a' && a[i] <= 'z') printf(\"%c\ else

printf(\"%c\ else printf(\"*\"); }

return 0; }

运行结果:t*M

26. (宋昕)

#include int main() {

char a[4][10] = {\"1234\ int i = 3;

char (*p)[10] = a;

printf(\"output string: \\n\"); for (p = a; p < a + 4; p++, i--) printf(\"%c\ return 0; }

运行结果:4cyi

27. (宋昕)

#include #include int main() {

char str1[30], str2[] = “your book”; scanf(“%s”, str1); strcpy(str1, str2);

printf(“\\n %s\\n %d\\n”, str1, strlen(str2)); return 0;

文案大全

标准实用

}

输入:you are a student<回车>

运行结果: your book 9

28. (宋昕)

#include #include int main()

{ char s1[10]=“java”,s2[10]=“basic”,s[10]; if(strcmp(s1,s2)) { strcpy(s,s1); puts(s);} printf(“%d,%s\\n”,strlen(s2),strcat(s2,s1)); return 0; }

运行结果: java

9,basicjava

29. (宋昕)

#include < stdio.h > #include < string.h > int main () {

char *p = “abcdefgh” , c[10] = { “XYZ” } ; p += 3 ;

puts ( strcat ( c , p ) ) ;

printf ( “%d\\n” , strlen ( c ) ) ; return 0; }

运行结果: XYZdefgh 8

30. (宋昕)

#include int main() {

int a[6][6], i, j; for(i=1;i<6;i++) for(j=1;j<6;j++)

文案大全

标准实用

a[i][j] = (i/j)*(j/i); for(i=1;i<6;i++) {

for(j=1;j<6;j++)

printf(\"%2d\ printf(\"\\n\"); }

return 0; }

运行结果: 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1

31. (宋昕)

#include int main() {

int i, f[10]; f[0]= f[1] = 1; for(i=2;i<10;i++)

f[i] = f[i-2] + f[i-1]; for(i=0;i<10;i++){

if(i%4 == 0) printf(\"\\n\"); printf(\"%3d\ }

return 0; }

运行结果: 1 1 2 3 5 8 13 21

32. (宋昕)

#include #include int main() {

char a[]=\"morming\ int i, j=0;

for(i=1;i<7;i++)

if(a[j]文案大全

标准实用

t = a[j]; a[j] = a[7]; a[7] = a[j]; puts(a); return 0; }

运行结果: mo

33. (于蕾)

#include #include void main() {

char s[12]=“abcdef”; scanf(“%s”,s); strcat(s,”xyz”); printf(“%s\\n”,s); }

运行结果: hijxyz

34. (于蕾)

#include void main() {

int a[3][3]={{3,4},{5,6},{7,8}}; int i,j,t=0; for(i=1;i<3;i++) for(j=0;j运行结果: t=20

35. (于蕾)

#include void main( ) {

int i,t,a[5]={1,2,3,4,5}; t=a[0];

文案大全

标准实用

for(i=1;i<5;i++) a[i-1]=a[i]; a[4]=t;

for(i=0;i<5;i++)

printf(\"%d\ printf(\"\\n\"); }

运行结果: 23451

36. (于蕾)

#include

void mystrcpy( char s1[ ] , char s2[ ]); void main( ) {

char a[50]=\"I am a teacher.\"; char b[]=\"You are a student.\"; printf( \" a = %s \\n\" , a ); mystrcpy( a , b );

printf( \" a = %s \\n\" , a ); }

void mystrcpy( char s1[ ] , char s2[ ]) {

int i = 0 ;

while( s2[i] != '\\0' ) {

s1[i] = s2[i]; i++; }

s1[i] = '\\0' ; }

运行结果:

a= I am a teacher. a= You are a student.

37. (于蕾)

#include void main() {

int i,j,k=0,a[3][3]={1,2,3,4,5,6}; for(i=0;i<3;i++)

for(j=i;j<3;j++) k=k+a[i][j]; printf(“¡ã%d”¡À,k);

文案大全

标准实用

}

运行结果: 17

38. (于蕾)

#include void main() {

int i,j=3,a[ ]={1,2,3,4,5,6,7,8,9,10}; for(i=0;i<5;i++) a[i]=i*(i+1); for(i=0;i<4;i++) j+=a[i]*3; printf(\"%d\\n\}

运行结果: 63

39. (于蕾)

#include void main() {

char c, string[81]= \"How are you?\"; int i, n=0, k=0;

for(i=0; c=string[i]; i++) {

if(c==' ') k=0; else if(k == 0) {

k = 1; n ++; } }

printf(\"%d\\n\" , n ); }

运行结果: 3

40. (于蕾)

#include #include

文案大全

标准实用

void main( ) {

char s[16]=“12345\\0\\\”;

printf(“%d,%d\\n”,strlen(s),sizeof(s)); }

运行结果: 5,16

第八章 结构体 出20道题

1.(王伟)

#include struct stri_type {

char ch1; char ch2; struct {

int a; int b; }ins; };

int main() {

struct stri_type ci;

ci.ch1='a'; ci.ch2='A'; ci.ins.a=ci.ch1+ci.ch2; ci.ins.b=ci.ins.a-ci.ch1;

printf(\"%d,%c\\n\ return 0; }

运行结果: 162,A

2.(王伟)

#include struct stud_type {

char num[11]; char name[11];

文案大全

标准实用

float score[3]; float average; };

int main() {

struct stud_type stu={\"200601\ stu.average=(stu.score[0]+stu.score[1]+stu.score[2])/3; printf(\"average=%5.2f\\n\ return 0; }

运行结果: average=78.33

3.(王伟)

#include union out {

int a[2]; struct {

int b; int c; }in; int d; };

int main() {

union out e; int i; e.in.b=1; e.in.c=2; e.d=3;

for(i=0;i<2;i++)

printf(\"%5d\ printf(\"\\n\"); return 0; }

运行结果: 3 2

4.(王伟)

#include

文案大全

标准实用

#define PI 3.14 struct cir_type {

float r; double area; };

int main() {

struct cir_type cir={5.0},*p=○ p->area=PI*p->r*p->r;

printf(\"area=%.3lf\\n\ return 0; }

运行结果: area=78.500

5.(王锋)

#include struct int_char { }; int main() { }

运行结果: 29 x

6.(王锋) #include int main() {

struct data

{ int m; int n; union

{

struct int_char x={9,'z'}; printf(\"%d\%5c\\n\return 0; int i; char ch;

文案大全

标准实用

};

int y; int z;

}da;

struct data intdata; intdata.m=3;intdata.n=6;

intdata.da.y=intdata.m+intdata.n; intdata.da.z=intdata.m-intdata.n;

printf(\"%5d%5d\\n\return 0;

}

运行结果: -3 -3

7.(王锋)

#include int main() {

int i;

float sum_average=0; struct student

{

int num; char name[10]; int score[2]; float average; }

运行结果:

1 zhangsan65.00

文案大全

};

struct student data[2]={{1,\"zhangsan\for(i=0;i<2;i++) {

data[i].average=(data[i].score[0]+data[i].score[1])/2.0; sum_average=sum_average+data[i].average; }

sum_average=sum_average/2; for(i=0;i<2;i++)

if(sum_average>data[i].average)

printf(\"%5d%10s%5.2f\

标准实用

8.(王锋)

#include struct int_data { int d1,d2;}; int main() { }

输入:20 30 40 50<回车>

运行结果: sum=150

struct int_data data[2]={{2,3},{5,6}}; int i; int sum=10; for(i=0;i<2;i++) }

printf(\"sum=%d \\n\return 0;

scanf(\"%d%d\sum=data[i].d1+data[i].d2+sum;

{

9.(王勇超)

#include int main( ) {

union exa {

struct {

int a; int b; }out; int c; int d; }e;

e.out.a=10; e.out.b=20; e.c=2; e.d=5;

printf(\"%d,%d\\n\ return 0; }

文案大全

标准实用

运行结果: 5,20

10.(王勇超) #include struct st {

int a; int b; union {

int e; int f; }c; };

int main( ) {

struct st y; y.a=10; y.c.e=20; y.c.f=y.a; y.b=y.c.e;

printf(\"%d,%d\\n\ return 0; }

运行结果: 10,10

11.(王勇超)

#include struct sta {

int a; char b; };

struct stb {

int a; char b;

struct sta c; };

文案大全

标准实用

int main( ) {

struct stb y; y.a=10; y.b='X'; y.c.a=y.a*2; y.c.b=y.b--;

printf(\"%d,%c\\n\ return 0; }

运行结果: 20,X

12.(王勇超) #include union st {

int a[2]; int b[2]; int c; };

int main( ) {

union st y; y.a[0]=10; y.b[1]=20; y.c=30;

printf(\"%d,%d\\n\ return 0; }

运行结果: 30,20

13.(于蕾)

#include struct two {

int n; char ch; };

文案大全

标准实用

void main( ) {

struct two ex1={5,'t'};

printf(\"%d,%c\\n\}

运行结果: 15,s

14.(于蕾)

#include struct two {

int n; char ch; };

void func(struct two ex2); void main() {

struct two ex1={6,'v'}; func(ex1);

printf(\"%d,%c\\n\ getchar(); }

void func(struct two ex2) {

ex2.n= ex2.n +20; ex2.ch= ex2.ch -1; }

运行结果: 6,v

15.(于蕾)

#include union exa{ struct{ int a; int b; }out; int c; int d; };

文案大全

标准实用

void main() {

union exa e; e.c=1; e.d=3;

e.out.a=e.c; e.out.b=e.d;

printf(\"%d,%d\\n\}

运行结果: 3,3

16.(于蕾)

#include struct stu {

int a; int b; struct poi {

int x; int y; }ins; };

void main() {

struct stu outs; outs.a=11; outs.b=4;

outs.ins.x=outs.a+outs.b; outs.ins.y=outs.a-outs.b;

printf(\"%d,%d\}

运行结果: 15,7

17.(宋昕)

#include struct abc {

int a, b, c; };

文案大全

标准实用

int main() {

struct abc s[2] = {{1,2,3},{4,5,6}}; int t;

t = s[0].a + s[1].c; printf(\"t=%d \\n\ return 0; }

运行结果: t=7

18.(宋昕)

#include struct st {

int x, y;

} data[2] = {1, 10, 2, 20}; int main() {

struct st *p = data ; printf(\"%d\\n\ printf(\"%d\\n\ return 0 ; }

运行结果: 10 2

19.(宋昕) struct n {

int x; char c; };

void func(struct n b) {

b.x = 20; b.c = 'y'; }

int main()

文案大全

标准实用

{

struct n a = {10, 'x'}; func(a);

printf(\"%d,%c\ return 0; }

运行结果: 10,x

20.(宋昕) int main() {

struct EXAMPLE {

struct {

int x; int y; } in; int a; int b; } e;

e.a = 1; e.b = 2;

e.in.x = e.a * e.b; e.in.y = e.a + e.b;

printf(\"%d,%d\ return 0; }

运行结果: 2,3

第九章 指针 共20道题

1. (王伟)

#include int main() {

int i=0,a[5]={11,12,13},*q; for(q=a;q文案大全

标准实用

{

*q+=5;

printf(\"%5d\ }

printf(\"\\n\"); return 0; }

运行结果:

16 17 18 5 5

2. (王伟)

#include void fun(int *p); int main() {

int a[5]={1,2,3,4,5},*r=a; fun(r);

printf(\"%d\\n\ return 0; }

void fun(int *p) {

p=p+2;

printf(\"%d\\n\}

运行结果: 3 1

3. (王伟)

#include int main() {

int a[3][3]={0,1,2,3,4,5,6,7,8}; int *p,(*q)[3]; int i=0;

for(q=a;qfor(p=*q;p<=*q+i;p++) printf(\"%5d\ printf(\"\\n\"); }

文案大全

标准实用

return 0; }

运行结果: 0

3 4

6 7 8

4. (王伟)

#include #include int main() {

char str[20]=\"I am a student.\ char *q=\"You are a teacher.\"; p=p+7; q=q+10;

strcpy(p,q); puts(str); return 0; }

运行结果:

I am a teacher.

5. (王锋)

#include

void swap(int x, int y) {

int z; z=x; x=y; y=z; }

void pswap(int *x, int *y) {

int z; z=*x; *x=*y; *y=z; }

void main() {

int a=3, b=2;

文案大全

标准实用

}

printf(\"first:a=%d, b=%d \\n\swap(a,b);

printf(\"second:a=%d,b=%d\\n\pswap(&a,&b);

printf(\"third:a=%d,b=%d\

运行结果: first:a=3, b=2 second:a=3,b=2 third:a=2,b=3

6. (王锋)

#include

void f(int a, int b, int *c, int *d) {

a=30; b=40; *c=a+b; *d=*d-a; }

void main() {

int a=10,b=20,c=30,d=40; f(a,b,&c,&d);

printf(\"%d,%d,%d,%d\}

运行结果: 10,20,70,10

7. (王锋)

#include

void ast(int *cp, int *dp) {

int x=4,y=3; *cp=++x+y; *dp=x-y; }

void main() {

int c, d; ast(&c,&d);

printf(\"%d\\n%d\\n\}

文案大全

标准实用

运行结果: 8 2

8. (王锋)

#include void main() {

char s[]=\"ABCD\ for(p=s+1;p运行结果: BCD CD D

9. (于蕾)

#include void main() {

char *p=\"I am a student.\"; p=p+3;

printf(\"%s\}

运行结果: m a student.

10. (于蕾)

#include void main( ) {

char *p=\"This is a programe.\"; p=p+10;

printf(\"%s\}

运行结果: programe.

11. (于蕾)

文案大全

标准实用

#include

void add(int *p, int n) {

int *pend = p + n; for( ; pvoid main( ) {

int a[5]={1,2,3,4,5}, *q = a; add(q, 5);

for(q=a; q < a+5; q++) printf(\"%4d\}

运行结果:

11 12 13 14 15

12. (于蕾)

#include int f(int x,int *y); void main() {

int a,b,c; a=3; b=5;

c=f(a,&b);

printf(\"%d,%d,%d\\n\}

int f(int x,int *y) {

int a=2; x=x+a; *y=x+a; return(a); }

运行结果: 3,7,2

13. (宋昕)

#include

void fun (int x , int *y ); int main()

文案大全

标准实用

{

int a = 2 , b = 3 , *c = &b; fun(a, c);

printf(\"a=%d, b=%d, c=%d\\n\ return 0; }

void fun( int x , int *y ) {

int a = 4; *y = x + a; x = *y; }

运行结果: a=2, b=6, c=6

14. (宋昕)

#include

void sub(int x, int y, int *z) {

*z = y - x; }

int main() {

int a, b, c; sub(10, 5, &a); sub(7, a, &b); sub(a, b, &c);

printf(\" % 4d, % 4d, % 4d\\n\ return 0; }

运行结果:

-5, -12, -7

15. (宋昕)

#include int main() {

char a[] = \"language\ p = a;

while (*p != 'u') {

printf(\" % c\

文案大全

标准实用

p++; }

return 0; }

运行结果: L A N G

16. (宋昕)

#include int stre(char str[]) {

int num = 0;

while(*(str + num) != '\\0') num++; return num; }

int main() {

char str[10], *p = str; gets(p);

printf(\" %d\\n\ return 0; }

输入:happy<回车>

运行结果: 5

17. (王勇超) #include void f(int x, int *y) {

x=x%10; *y=*y/10+x; }

int main() {

int a=88,b=99,*c; c=&b; f(a,c);

printf(\"%d,%d\\n\ return 0; }

文案大全

标准实用

运行结果: 88,17

18. (王勇超) #include void main() {

char a[][7]={ \"Teacher\ char *p=a[0]; p=p+3;

printf(\"%s\\n%s\\n\}

运行结果: TeacherTom cherTom

19. (王勇超) #include void main() {

char a[][7]={ \"Teacher\ char (*p)[7]=a;

printf(\"%s\\n%s\\n\}

运行结果: TeacherTom Tom

20. (王勇超) #include

void ast(int x, int y, int *a, int *b) {

*a=x+y; *b=*a-y; }

void main() {

int a, b, c, d; a=10; b=20;

ast(a,b,&c,&d);

文案大全

标准实用

printf(\"%d,%d\\n\}

运行结果: 30,10

文案大全

因篇幅问题不能全部显示,请点此查看更多更全内容