C语言题目11

IT小小龙 posted @ 2014年4月06日 16:20 in C with tags 统计字符个数 , 592 阅读
//输入一串字符串,以回车结束,统计其中的英文字符、数字字符、空格和其他字符数目;
#include<stdio.h>
int main()
{
  char c;
  int chars = 0; 
  int numbers = 0;
  int spaces = 0;
  int others = 0;
  printf("请输入一个字符串,输入完成后敲击回车:");
  while(1)
    {
      c = getchar();
      if(c=='\n')
	{
	  break;
	}
      else
	{
	  if(c>='0' && c<='9')
	    {
	      numbers++;
	    }
	  else if((c>='a' && c<='z')||(c>='A' && c<='Z'))
	    {
	      chars++;
	    }
	  else if(c == ' ')
	    {
	      spaces++;
	    }
	  else
	    {
	      others++;
	    }
	}
    }
  printf("char=%d\tnumber=%d\tspace=%d\tother=%d\n", chars, numbers, spaces, others);
  return 0;
}
Avatar_small
Maha 10th Important 说:
2022年8月24日 15:32

Maharashtra SSC Question Paper 2023 Download – Maha 10th Important Question Paper 2023 PDF, SSC Question Paper 2023 Maharashtra Board, Maharashtra, Maha 10th Important Question Paper 2023 PDF Directorate of Government Examination has been released the Important Question Paper for Secondary School Leaving Certificate Class 10. The SSC examination is set to begin from 1st week of March to last week of March 2023.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter