当前位置: 代码迷 >> C语言 >> [求助]帮我看看这些程序的结果是什么!
  详细解决方案

[求助]帮我看看这些程序的结果是什么!

热度:119   发布时间:2007-01-11 23:04:33.0
  没力气看题目了
----------------解决方案--------------------------------------------------------

读程序,写出程序执行结果
1.void main()
{ int x= - 9, y ;
if(x>0) y=10 ;
else if(x= =0) y=0;
else if(x<-5) y= -3;
else y= -2;
printf(“%d\n”,y)//-3
}
2.void main()
{ int a, b, c,x ;
a=b=c=1;
x=3 ;
if ( !a) x-- ;
else if (b)
if (c) x=3;
else x=4;
printf(“%d\n”, x);//3
}
3.void main()
{ int x=2,y=6;
int j;
for(j=1 ; y>0 ; y - - ) j=j*x;
printf(“j=%d\n”,j);//64
}
4.void main()
{ int a=5, b=8;
printf(“a=%d b=%d\n”, a,b) ;//a=5 b=8
a=a+b; b=a-b; a=a-b;
printf(“a=%d b=%d\n”, a,b) ; }//a=8 b=5
5. int fib(int g)
{ switch(g)
{ case 0: return 0;
case 1:
case 2: return 1;
}
return -1;
}
void main()
{ printf(“%d\n”, fib(2)) ; //1
}
6. void main()
{ int s=’3’;
switch(s-'2')
{ case 0 ;
case 1 : putchar(s+4);
case 2 : putchar(s+4); break;
case 3 : putchar(s+3);
default : putchar(s+2);//77
}
}
7.void main()
{ int x=2;
switch(1+x)
{ case 0 ;
case 1 : printf(“apple”); break ;
case 2 : printf(“hello”); break;
case 3 : printf(“world”);
default : printf(“thank you”);//worldthank you
}
}
8.void main()
{ int x,y;
for(x=1,y=1; y<=50; y++)
{ if(x>=10) break;
if(x%2==1) {x+=5; continue ;}
x-=3;
}
printf("%d %d\n",x,y);//10 6
} 
9.void main()
{ int i=1;
while (i<10)
if(++i%5!=3) continue ;
else printf("%d ",i);//8
} 
10.void main()
{ int n= -5 ;
while(n++)
printf("%2d", ++n) //; 死循环,-3 -1 1...
}
11.void main()
{ int t, n=15;
t=0;
do {
t+=n;
n-=2;
} while (n>0);
printf(“%d\n”, t);//1 }
12.void main()
{ char *p, str[20]="xyz " ;
p=" ABCDEFG" ;
strcpy(str+1 , p+1) ;
printf("%s", str) ;//xBCDEFG
}
13.void main()
{ char *p=”abcdba”,*q;
int flag=1;
q=p+strlen(p)-1;
while(p<q) if(*p++!=*q- -) flag=0;
if(flag) puts(“yes”);
else puts(“no”) ; //no
}
14.void main ( )
{ char a[20]=”very lucky”, c ;
int i, j;
j= strlen(a)-1 ;
for (i=0; j>i; i++,j--)
{ c=*(a+i); *(a+i)=*(a+j); *(a+j)=c;
}
puts(a);//ykcul yrev
}
15. void main()
{ char x[]="abcxyz";
char *ptr;
for(ptr=&x[2];ptr<x+6;ptr++)
printf("%s\n",ptr);//cxyz
注意 xyz
yz
z
}
16.void main()
{ char a[]="language", *p=a;
int k=0;
while(*p)
{ if(*p<’f’) ++k ; p++; }
printf(“%s %d\n”,a,k) ; //language 3
}
17. void main()
{ int k,a[10],*p=a ;
for(k=1;k<10;k++) *(p+k-1)=k;
for(k=0;k<5;k++) *(p+9-k)=*(p+k);
for(k=0;k<10;k++) printf(“%3d”,*p++); //1 2 3 4 5 5 4 3 2 1
}
18.int fun(int x)
{ return(x>0 ? x : -x); }
void main()
{ int a=-5;
printf(“%d, %d\n”,a,fun(a));//-5,5
}
19. ex ( )
{ static int x=5 ;
- -x ;
printf(“%d”,x) ;
}
void main ( )
{ ex ( ); ex ( ); ex ( ); } //432
20.int d=2 ;
int fun(int p)
{ static int d=3 ;
d+=p;
printf("%3d" , d) ;
return(d) ;
}
void main( )
{ printf("%3d\n" , fun(2+fun(d))) ; } //5 12 12 //????
21.void main()
{ int n1,n2;
n2=5678;
while(n2!=0)
{ n1=n2%10;
n2=n2/10;
printf("%d",n1); //8765
}
}
22void main()
{ char *p=”China University of Petroleum!”, *p1;
int n=1;
p1=p;
while(*++p)n++;
printf(%c ,%d\n”,p1+20,n); //?,33 //????
}
呵呵
今天可是学习了哦!!


----------------解决方案--------------------------------------------------------
朋友。谢谢
----------------解决方案--------------------------------------------------------
朋友,谢谢!
----------------解决方案--------------------------------------------------------
谢谢两位朋友了!
----------------解决方案--------------------------------------------------------


----------------解决方案--------------------------------------------------------
  相关解决方案