#include "stdio.h"
void main()
{int x=0,c=0,b=0,n=0,k=0;
while (x!='\n')
{x=getchar();
if (48<=x&&x<=57) c++;
else if (65<=x&&x<=90||97<=x&&x<=122) k++;
else if (x==32) b++;
else n++;
}
printf("共有%d个数字\n%d个字母\n%d个字符\n%d个空格",c,k,n,b);
}帮我看下这为什么每次都会多出了一个字符的啊
结束的回车被计算了一次,才到while那里判断并推出。
改为:
void
main()
{int
x=0,c=0,b=0,n=0,k=0;
x=getchar();
while
(x!='\n')
{
if
(48<=x&&x<=57)
c++;
else
if
(65<=x&&x<=90||97<=x&&x<=122)
k++;
else
if
(x==32)
b++;
else
n++;
x=getchar();
}
printf("共有%d个数字\n%d个字母\n%d个字符\n%d个空格",c,k,n,b);
}
改为:
void
main()
{int
x=0,c=0,b=0,n=0,k=0;
x=getchar();
while
(x!='\n')
{
if
(48<=x&&x<=57)
c++;
else
if
(65<=x&&x<=90||97<=x&&x<=122)
k++;
else
if
(x==32)
b++;
else
n++;
x=getchar();
}
printf("共有%d个数字\n%d个字母\n%d个字符\n%d个空格",c,k,n,b);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 推荐于2017-12-15
结束的回车被计算了一次,才到while那里判断并推出。
改为:
void main()
{int x=0,c=0,b=0,n=0,k=0;
x=getchar();
while (x!='\n')
{
if (48<=x&&x<=57) c++;
else if (65<=x&&x<=90||97<=x&&x<=122) k++;
else if (x==32) b++;
else n++;
x=getchar();
}
printf("共有%d个数字\n%d个字母\n%d个字符\n%d个空格",c,k,n,b);
}本回答被提问者采纳
改为:
void main()
{int x=0,c=0,b=0,n=0,k=0;
x=getchar();
while (x!='\n')
{
if (48<=x&&x<=57) c++;
else if (65<=x&&x<=90||97<=x&&x<=122) k++;
else if (x==32) b++;
else n++;
x=getchar();
}
printf("共有%d个数字\n%d个字母\n%d个字符\n%d个空格",c,k,n,b);
}本回答被提问者采纳
第2个回答 2019-10-04
结束的回车被计算了一次,才到while那里判断并推出。
改为:
void
main()
{int
x=0,c=0,b=0,n=0,k=0;
x=getchar();
while
(x!='\n')
{
if
(48<=x&&x<=57)
c++;
else
if
(65<=x&&x<=90||97<=x&&x<=122)
k++;
else
if
(x==32)
b++;
else
n++;
x=getchar();
}
printf("共有%d个数字\n%d个字母\n%d个字符\n%d个空格",c,k,n,b);
}
改为:
void
main()
{int
x=0,c=0,b=0,n=0,k=0;
x=getchar();
while
(x!='\n')
{
if
(48<=x&&x<=57)
c++;
else
if
(65<=x&&x<=90||97<=x&&x<=122)
k++;
else
if
(x==32)
b++;
else
n++;
x=getchar();
}
printf("共有%d个数字\n%d个字母\n%d个字符\n%d个空格",c,k,n,b);
}
第3个回答 2019-04-28
结束的回车被计算了一次,才到while那里判断并推出。
改为:
void
main()
{int
x=0,c=0,b=0,n=0,k=0;
x=getchar();
while
(x!='\n')
{
if
(48<=x&&x<=57)
c++;
else
if
(65<=x&&x<=90||97<=x&&x<=122)
k++;
else
if
(x==32)
b++;
else
n++;
x=getchar();
}
printf("共有%d个数字\n%d个字母\n%d个字符\n%d个空格",c,k,n,b);
}
改为:
void
main()
{int
x=0,c=0,b=0,n=0,k=0;
x=getchar();
while
(x!='\n')
{
if
(48<=x&&x<=57)
c++;
else
if
(65<=x&&x<=90||97<=x&&x<=122)
k++;
else
if
(x==32)
b++;
else
n++;
x=getchar();
}
printf("共有%d个数字\n%d个字母\n%d个字符\n%d个空格",c,k,n,b);
}