输入一串字符,求其中英文字母,空格,数字,其他字符的数量
#include<stdio.h>intmain(){intletter=0,space=0,number=0,others=0;charc;for(;c!='\n';)...
#include <stdio.h>
int main()
{
int letter=0,space=0,number=0,others=0;
char c;
for(;c!='\n';)
{
scanf("%c",&c);
if(('a'<=c&&c<='z')||('A'<=c&&c<='Z'))
letter++;
else if(c==' ')
space++;
else if('0'<=c&&c<='9')
number++;
else
others++;
}
printf("%d %d %d %d\n",letter,space,number,--others);
}
为啥在“ for(;c!='\n';)”上加;在c前?还有最后others前加- -? 展开
int main()
{
int letter=0,space=0,number=0,others=0;
char c;
for(;c!='\n';)
{
scanf("%c",&c);
if(('a'<=c&&c<='z')||('A'<=c&&c<='Z'))
letter++;
else if(c==' ')
space++;
else if('0'<=c&&c<='9')
number++;
else
others++;
}
printf("%d %d %d %d\n",letter,space,number,--others);
}
为啥在“ for(;c!='\n';)”上加;在c前?还有最后others前加- -? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询