注册 登录
编程论坛 C++教室

求解

moyurongxu 发布于 2012-12-04 15:30, 395 次点击
将以下程序补充完整,实现:输入一行字符,分别统计出其中英文字母、空格、数字和其他字母的个数。
#include <stdio.h>
int main( )
{
  char c;
  int letter=0,space=0,digit=0,other=0;
  printf("input a line letter:\n");
      __________           /*读取当前字符,如不为回车符则进行统计*/
    {
     if(c>='a' && c<='z'||c>='A' && c<='Z')
      letter++;
     else if(c==' ')
       space++;
else   __________                     
       digit++;
     else
       other++;
    }
 printf(" letter=%d,space=%d,digit=%d,other=%d\n",letter,space,digit,other);
 return 0;
}
6 回复
#2
azzbcc2012-12-04 15:56
这题不难,楼主自己想想先
#3
糊涂无罪2012-12-04 16:56
连个循环都没有,怎么统计
#4
moyurongxu2012-12-05 22:20
#include <stdio.h>
 int main( )
 {
   char c;
   int letter=0,space=0,digit=0,other=0;
   printf("input a line letter:\n");
      getcher()         /*读取当前字符,如不为回车符则进行统计*/
     {
      if(c>='a' && c<='z'||c>='A' && c<='Z')
       letter++;
      else if(c==' ')
        space++;
 else   if(c>=0&&c<=9)                     
        digit++;
      else
        other++;
     }
printf(" letter=%d,space=%d,digit=%d,other=%d\n",letter,space,digit,other);
return 0;
 
是否
#5
moyurongxu2012-12-05 22:21
不会如可输入一横字符
#6
azzbcc2012-12-05 22:39
while((c = getchar())!= '\n')
#7
moyurongxu2012-12-12 18:04
几天没上,不好意思
1