[求助]帮我看看这些程序的结果是什么!
读程序,写出程序执行结果 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);
}
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.void main()
{ int x=2,y=6;
int j;
for(j=1 ; y>0 ; y - - ) j=j*x;
printf(“j=%d\n”,j);
}
4.void main()
{ int a=5, b=8;
printf(“a=%d b=%d\n”, a,b) ;
a=a+b; b=a-b; a=a-b;
printf(“a=%d b=%d\n”, a,b) ; }
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)) ;
}
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);
}
}
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”);
}
}
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);
}
9.void main()
{ int i=1;
while (i<10)
if(++i%5!=3) continue ;
else printf("%d ",i);
}
10.void main()
{ int n= -5 ;
while(n++)
printf("%2d", ++n) ;
}
11.void main()
{ int t, n=15;
t=0;
do {
t+=n;
n-=2;
} while (n>0);
printf(“%d\n”, t);
}
12.void main()
{ char *p, str[20]="xyz " ;
p=" ABCDEFG" ;
strcpy(str+1 , p+1) ;
printf("%s", str) ;
}
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”) ;
}
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);
}
15. void main()
{ char x[]="abcxyz";
char *ptr;
for(ptr=&x[2];ptr<x+6;ptr++)
printf("%s\n",ptr);
}
16.void main()
{ char a[]="language", *p=a;
int k=0;
while(*p)
{ if(*p<’f’) ++k ; p++; }
printf(“%s %d\n”,a,k) ;
}
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++);
}
18.int fun(int x)
{ return(x>0 ? x : -x); }
void main()
{ int a=-5;
printf(“%d, %d\n”,a,fun(a));
}
19. ex ( )
{ static int x=5 ;
- -x ;
printf(“%d”,x) ;
}
void main ( )
{ ex ( ); ex ( ); ex ( ); }
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))) ; }
21.void main()
{ int n1,n2;
n2=5678;
while(n2!=0)
{ n1=n2%10;
n2=n2/10;
printf("%d",n1);
}
}
22.void main()
{ char *p=”China University of Petroleum!”, *p1;
int n=1;
p1=p;
while(*++p)n++;
printf(%c ,%d\n”,p1+20,n);
}
----------------解决方案--------------------------------------------------------
谢谢,各位帮个忙,后天急用,
----------------解决方案--------------------------------------------------------
各位帮个忙,做一道题也行,谢谢!!!
----------------解决方案--------------------------------------------------------
第一题-3
----------------解决方案--------------------------------------------------------
第二题3
----------------解决方案--------------------------------------------------------
第三题:
j=64
----------------解决方案--------------------------------------------------------
第四:
a=5 b=8
a=8 b=5
----------------解决方案--------------------------------------------------------
第五:
1
----------------解决方案--------------------------------------------------------
第六:
77
----------------解决方案--------------------------------------------------------
第七:
worldthank you
----------------解决方案--------------------------------------------------------