11.
#include "stdio.h"main(){ char c;c=getchar();while(c!='?') {putchar(c);c=getchar();}}
如果从键盘输入 abcde?fgh(回车)
运行结果为: abcde
12.
#include <stdio.h>main(){ char c;while((c=getchar())!=’$’){if(‘A’<=c&&c<=‘Z’) putchar(c);else if(‘a’<=c&&c<=‘z’) putchar(c-32);}}
当输入为 ab*AB%cd#CD$时,运行结果为: ABABCDCD
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
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
17.
#include <stdio.h>main(){int y=9;for(;y>0;y- -)if(y%3==0){printf(%d”,- -y);}}
运行结果为: 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 4main(){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 58 13 21 34
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");
}
}
运行结果为:****