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

源程序:

#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;
}

运行结果:

 

posted @   bobo哥  阅读(1952)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示