0
点赞
收藏
分享

微信扫一扫

c语言 输入一行文字(不超过80个字符),求出大写字母、小写字母、空格和其他字符的个数。

金穗_ec4b 2022-06-08 阅读 77

源程序:

#include <stdio.h>
int main()
{
  int upper=0,lower=0,digit=0,space=0,other=0,i=0;
  char *p,s[80];
  printf("请输入一串字符,包括大写字母、小写字母、数字、空格和其他字符,不超过80个:\n");
  while ((s[i]=getchar())!='\n')     i++;
  p=&s[0];
  while (*p!='\n')
  {
    if (('A'<=*p) && (*p<='Z'))
      ++upper;
    else if (('a'<=*p) && (*p<='z'))
      ++lower;
    else if (*p==' ')
      ++space;
    else if ((*p<='9') && (*p>='0'))
      ++digit;
    else
    ++other;
  p++;
  }
  printf("大写字母个数:%d\n",upper);
  printf("小写字母个数:%d\n",lower);
  printf("数字个数:%d\n",digit);
  printf("空格个数:%d\n",space);
  printf("其他字符个数:%d\n",other);
  return 0;
}

运行结果:

c语言 输入一行文字(不超过80个字符),求出大写字母、小写字母、空格和其他字符的个数。_git

 


举报

相关推荐

C语言计算大写字母的个数

0 条评论