13.
#include <stdio.h>
main()
{ int x, y =0;
for(x=1;x<=10;x )
{ if(y>=10)
break;
y=y x;
}
printf(“%d %d”,y,x);
}
运行结果为:10 5
14.
#include<stdio.h>
main( )
{ char ch;
ch=getchar( );
switch(ch)
{ case ‘A’ : printf(“%c”,’A’);
case ‘B’ : printf(“%c”,’B’); break;
default: printf(“%s\n”,”other”);
} }
当从键盘输入字母A时,运行结果为:AB
15.
#include <stdio.h>
main( )
{ int a=1,b=0;
scanf(“%d”,&a);
switch(a)
{ case 1: b=1;break;
case 2: b=2;break;
default : b=10;}
printf("%d ", b);
}
若键盘输入5,运行结果为:10
16.
#include <stdio.h>
main()_
{ char grade=’C’;
switch(grade)
{ case ‘A’: printf(“90-100\n”);
case ‘B’: printf(“80-90\n”);
case ‘C’: printf(“70-80\n”);
case ‘D’: printf(“60-70\n”); break;
case ‘E’: printf(“<60\n”);
default : printf(“error!\n”);
}
}
运行结果为:
70-80
60-70
17.
#include <stdio.h>
main()
{ int y=9;
for(;y>0;y- -)
if(y%3==0)
{ printf(%d”,- -y);
continue;
}
}
运行结果为:
852
18.
#include <stdio.h>
main()
{ int i,sum=0; i=1;
do{ sum=sum i; i ; }while(i<=10);
printf(“%d”,sum);
}
运行结果为: 55
19.
#include <stdio.h>
#define N 4
main()
{ int i;
int x1=1,x2=2;
printf("\n");
for(i=1;i<=N;i )
{ printf("%4d%4d",x1,x2);
if(i%2==0)
printf("\n");
x1=x1 x2;
x2=x2 x1;
}
}
运行结果为:
1 2 3 5
8 13 21 34
20
#include <stdio.h>
main( )
{ int x, y;
for(x=30, y=0; x>=10, y<10; x--, y )
x/=2, y =2;
printf(“x=%d,y=%d\n”,x,y);
}
运行结果为:
x=0,y=12
21.
#include <stdio.h>
#define N 4
main( )
{ int i,j;
for(i=1;i<=N;i )
{ for(j=1;j<i;j )
printf(" ");
printf("*");
printf("\n");
}}
运行结果为:
*
*
*
*