C语言练习题带答案

}

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

{for(j=0;j<=1;j++)

printf(\ } }

运行结果为:

1 4 2 5 3 6

12.

#include f(int b[],int n) {int i,r; r=1;

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

r=r*b[i]; return (r); }

main()

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

printf(“%d\\n”,x); }

运行结果为: 24 13.

#include\main() {int j,k;

static int x[4][4],y[4][4]; for(j=0;j<4;j++) for(k=j;k<4;k++) x[j][k]=j+k; for(j=0;j<4;j++) for(k=j;k<4;k++) y[k][j]=x[j][k];

for(j=0;j<4;j++) for(k=0;k<4;k++)

printf(\}

运行结果为:

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

函数

1.

#include int Sub(int a, int b) {return (a- b);} main()

{int x, y, result = 0; scanf(\ result = Sub(x,y ) ;

printf(\}

当从键盘输入:6,3运行结果为: result =3 2.

#include

int min( int x, int y ) { int m;

if ( x> y ) m = x; else m = y; return(m); }

main() {

int a=3,b=5,abmin ; abmin = min(a,b); printf(“min is %d”, abmin); }

运行结果为: min is 5

3.

#include func(int x) { x=10;

printf(“%d, ”,x); }

main( )

{ int x=20; func(x);

printf(“%d”, x); }

运行结果为: 10, 20

4.

#include int m=4;

int func(int x,int y) { int m=1;

return(x*y-m); }

main()

{int a=2,b=3;

printf(\

printf(\ }

运行结果为: 4 1 5.

#include int fun(int a, int b) { if(a>b) return(a); else return(b); }

main()

{ int x=15, y=8, r; r= fun(x,y);

printf(\}

运行结果为:r=15 6.

#include int fac(int n) { int f=1,i;

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

f=f * i; return(f); }

main() { int j,s;

scanf(“%d”,&j); s=fac(j);

printf(\}

如果从键盘输入3, 运行结果为:3!=6

7.

#include

unsigned fun6(unsigned num) { unsigned k=1;

do

{ k*=num; num/=10; }while(num); return k; }

main()

{ unsigned n=26;

printf(“%d\\n”,fun6(n)); }

运行结果为:12 8.

#include int max(int x, int y); main() { int a,b,c a=7;b=8; c=max(a,b);

printf(\}

max(int x, int y) { int z;

z=x>y? x : y; return(z) ; }

运行结果为: Max is 8

指针

1.

# include < stdio .h > main ( )

{ int x[ ] = {10, 20, 30, 40, 50 }; int *p ; p=x;

printf ( “%d”, *(p+2 ) ); } 运行结果为: 30 2.

#include main( )

{ char s[]=”abcdefg”; char *p; p=s;

printf(“ch=%c\\n”,*(p+5)); }

运行结果为: ch=f 3.

#include main ( )

{ int a[]={1, 2, 3, 4, 5} ; int x, y, *p; p=a;

x=*(p+2);

printf(\:%d \\n\; }

运行结果为: 1:3 4.

#include main()

{ int arr[ ]={30,25,20,15,10,5}, p++;

printf(“%d\\n”,*(p+3)); }

运行结果为:10

*p=arr;

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4