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

2024-11-17 05:55:37
推荐回答(1个)
回答(1):

#include
using namespace std;

int main(void)
{
int num,largeLetter,smallLetter,other;
num = largeLetter = smallLetter = other = 0;
char *s = new char[100];
cout<<"请输入一串字符:"< 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<<"数字个数为:"< cout<<"大写字母个数为:"< cout<<"小写字母个数为:"< cout<<"其他字符个数为:"<}