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

运行结果:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM