用C语言编写:输入20个字符,存放在一个字符数组中,然后分别统计其中数字、英文字母和其它字符的个数

2025-04-06 10:10:40
推荐回答(1个)
回答1:

#include
int main()
{
char str[100];
int i=0;
int num=0,ch=0,blank=0,other=0;

gets(str);
while(str[i]!='\0')
{
if((str[i]>='A' && str[i]<='Z') || (str[i]>='a' && str[i]<='z'))
ch++;//字母
else if(str[i]>='0' && str[i]<='9')
num++;//数字
else if(str[i]==' ')
blank++;//空格
else
other++;

i++;

printf("数字%d个,字母%d个,空格%d个,其他%d个\n",num,ch,blank,other);
return 0;