简单的编辑程序问题,速求答案!

来源:百度知道 编辑:UC知道 时间:2024/06/07 06:28:00
输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。注意是用循环。
大家帮忙呀,别光看热闹呀!

不知道你要用什么语言,用C语言编一个.
#include<stdio.h>
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???

你想要用什么编程语言编写呢?

经常练的题