C语言题目1

IT小小龙 posted @ 2014年4月03日 15:57 in C with tags 统计字符个数 , 444 阅读
//用C编写程序:输入一串字符,计算其中的字符、数字、其他字符的个数并输出。
#include<stdio.h>
int main()
{
  char c;
  int chars = 0; 
  int numbers = 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
	    {
	      others++;
	    }
	}
    }
  printf("char=%d\tnumber=%d\tother=%d\n", chars, numbers, others);
  return 0;
}
Avatar_small
Uttarakhand Board Qu 说:
2022年9月17日 16:26

UK Board Model Paper 2023 Class 7 Pdf Download Uttarakhand School Education Board Term1 & Term2 Exam Solved Question Bank for SCERT & NCERT Syllabus Hindi Medium, English Medium & Urdu Medium Students at Uttarakhand Board Question Paper Class 7 Uttarakhand Board of School Education (UBSE) Subject experts have designed and suggested Sample Paper for all High School Level Class 7th Standard Students to know the new exam scheme or question pattern of Term1 & Term2 exams.


登录 *


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