小程序18

来源:互联网 发布:视频gif截取 mac 编辑:程序博客网 时间:2024/05/08 21:40

//输入一行字符串,分别统计出其中英文字符 空格 数字和其他字符的个数
#include<iostream>

using namespace std;

void main()

{
 char c;

    int letters=0,spaces=0,digits=0,others=0;//初始化

 printf("please input some characters/n");//任意输入字符串

 while((c=getchar())!='/n')//利用getchar()输入很好 /n不是不输入

 {
  if(c>='a'&&c<='z'||c>='A'&&c<='Z')

   letters++;

  else if(c==' ')//表示空格

   spaces++;

  else if(c>='0'&&c<='9')

   digits++;

  else

   others++;

 }

  printf("all in all: char=%d spaces=%d digits=%d others=%d/n",letters,spaces,digits,others);


}

原创粉丝点击