#include <stdio.h>
#include <stdlib.h>
//本程序统计输入板上数字,空格,回车和其他等字符
int main()
{
int c,i,nwhrite,nother,ndight[10];
nwhrite = nother = 0;
for(i = 0; i < 10;i ++)
ndight[i] = 0;
while((c = getchar()) != EOF)
switch(c)
{//依次执行各分支程序的做法有好处也有坏处。
//好的一面是它可以把若干个分支组合在一起完成一个任务、
//不好的一面在于从一个分支直接进入下一个分支的执行的做法并不
//健全,在做修改程序时很容易出错。
case '0':case '1':case '2':case '3':case '4':
case '5':case '6':case '7':case '8':case '9':
ndight[c - '0'] ++;
break;
case ' ':
case '\n':
case '\t':
nwhrite ++;
break;
default:
nother ++ ;
break;
}
printf("digits = ");
for(i = 0; i < 10;i ++)
printf(" %d ",ndight[i] );
printf(",white space = %d,other = %d\n",nwhrite,nother);
return 0;
}
swirch语句的应用
最新推荐文章于 2021-05-27 20:55:05 发布