#include <iostream>
using namespace std;
void statiscits(char ch[])
{
int i,zimu = 0, shuzi = 0, kongge = 0, qita = 0;
for (i = 0;ch[i] != '\0';i++)
{
if ((ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= 'A' && ch[i] <= 'Z'))
zimu++;
else if (ch[i] >= '0' && ch[i] <= '9')
shuzi++;
else if (ch[i] ==' ')
kongge++;
else
qita++;
}
cout <<"字母的个数为" << zimu << endl;
cout << "数字的个数为"<<shuzi<<endl;
cout << "空格的个数为"<<kongge<<endl;
cout << "其它的个数为"<<qita<<endl;
}
int main()
{
cout << "输入字符串" << endl;
char a[80];
gets_s(a);
statiscits(a);
}
4.编写一函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其他字符的个数,在主函数中输入字符串以及输出统计结果。
最新推荐文章于 2024-05-31 14:42:05 发布