栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > C++面试题库

输入一行文字,找出其中大写字母、小写字母、空格、数字、及其他字符各有多少。

输入一行文字,找出其中大写字母、小写字母、空格、数字、及其他字符各有多少。

解:   #include <stdio.h>
      main()
       { int upper=0.lower=0,digit=0,space=0,other=0,i=0;
         char *p,s[20];
          printf(“Input string:”);
          while ((s[i]=getcher())!=’n’) i++;
         p=&s[0];
          while(*p!=’n’)
               { if((‘A’<=*p)&&(8p<=’Z’))
                  ++upper;
                else if((‘a’<=*p)&&(*p<=”z’))
                    ++lower;
                 else if(8p= =’’)
                       ++space;
                    else if((*p<=’9’)&&(*p>=’0’))
                       ++dight;
                     else
                        ++other;
                     p++;
                   }
           printf(“upper case:%d lower case:%d”,upper,lower);
        printf(“space:%dndigit:%dnother:%dn”,space,digit,other);
       }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/265932.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号