|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Omega. 于 2020-11-25 23:04 编辑
#include<stdio.h>
int main()
{
int ch=0,space=0,num=0,n=0;
char c;
while(c=getchar()!='\n')
{
if((c>='a')&&(c<='z')||(c>='A'&&c<='Z'))
ch=ch+1;
else if(c>=0&&c<=9)
num=num+1;
else if(c==' ')
space=space+1;
else
n=n+1;
}
printf("character:%d\nnumber:%d\nspace:%d\nnone:%d\n",ch,num,space,n);
printf("\n");
return 0;
}
错误在注释中了
- #include<stdio.h>
- int main()
- {
- int ch = 0, space = 0, num = 0, n = 0;
- char c;
- while ((c = getchar()) != '\n')// 是 c 接收到的字符不为回车键,而不是 getchar() 不为回车键,所以要加括号
- {
- if ((c >= 'a') && (c <= 'z') || (c >= 'A'&&c <= 'Z'))
- ch = ch + 1;
- else if (c >= '0' && c <= '9') // 数字也是字符,要加单引号
- num = num + 1;
- else if (c == ' ')
- space = space + 1;
- else
- n = n + 1;
- }
- printf("character:%d\nnumber:%d\nspace:%d\nnone:%d\n", ch, num, space, n);
- printf("\n");
- return 0;
- }
复制代码
|
|