不知道你要用什么语言,用C语言编一个.
#include
int isChar(char ch){/*是字母返回1,否则返回0*/
return (ch >= 'A' && ch <= 'Z' )
|| (ch >= 'a' && ch <= 'z');
}
int main(){
int charNum = 0;
int digitNum = 0;
int spaceNum = 0;
int otherNum = 0;
char ch;
do{
ch = getchar();
if( ch == '\n')break;
if(ch >= '0' && ch <= '9') digitNum++;
else if( isChar(ch) ) charNum++;
else if( ch == ' ') spaceNum++;
else otherNum++;
}while(1);
printf("char number : %d\ndigit number : %d\nspace number: %d\nother number:%d\n",
charNum,digitNum,spaceNum,otherNum);
}
在下也是初学者,共同进步吧.
我觉得把这种问题没什么人愿意回答
哈~貌似上大学的时候有道考试题是这个,不会是你在考试呢吧
你在什么环境中输入的字符??office???
你想要用什么编程语言编写呢?
经常练的题