编写一个程序统计输入字符串中:
各个数字、空白字符、以及其他所有字符出现的次数。
#include<stdio.h> int main() { int i=0,len=0; int count=0,COUNT=0,count0=0,count1=0,\ count2=0,count3=0,count4=0,count5=0,\ count6=0,count7=0,count8=0,count9=0; char str[100]; gets(str); len=strlen(str); for(i=0;i<len;i++) { if((str[i]>='0')&&(str[i]<='9')) { switch(str[i]) { case '0': (count0)++; break; case '1': (count1)++; break; case '2': (count2)++; break; case '3': (count3)++; break; case '4': count4++; break; case '5': count5++; break; case '6': count6++; break; case '7': count7++; break; case '8': count8++; break; case '9': count9++; break; default: break; } } else if(str[i]==' ') { count++; } else COUNT++; } printf("%d\n",len); printf("count=%d COUNT=%d count0=%d count1=%d count2=%d \ count3=%d count4=%d count5=%d count6=%d count7=%d \ count8=%d count9=%d \n",count,COUNT,count0,count1,\ count2,count3,count4,count5,count6,count7,count8,count9); return 0; }