编写程序,统计输入的字符串中大写英文字母,小写英文字母,数字和其它字符的个数.(用数组 C++ )

如题所述

#include <iostream>
using namespace std;

int main(void)
{
int num,largeLetter,smallLetter,other;
num = largeLetter = smallLetter = other = 0;
char *s = new char[100];
cout<<"请输入一串字符:"<<endl;
gets(s);
while (*s != '\0')
{
if (*s>='A' && *s<='Z')
largeLetter++;
else if(*s>='a' && *s<='z')
smallLetter++;
else if (*s>='0' && *s<='9')
num++;
else
other++;
s++;
}
cout<<"数字个数为:"<<num<<endl;
cout<<"大写字母个数为:"<<largeLetter<<endl;
cout<<"小写字母个数为:"<<smallLetter<<endl;
cout<<"其他字符个数为:"<<other<<endl;
}
温馨提示:答案为网友推荐,仅供参考
相似回答