|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
/*统计数字、字母、空格等、*/
#include <stdio.h>
int main ()
{
char ch;
int space, num, others, letter;
printf ( "please input:" );
space = 0;
num = 0;
others = 0;
letter = 0;
ch = getchar ();
while ( ch != '\n')
{
if ( ch > 'a' && ch < 'z')
{
letter ++;
}
else if ( ch == ' ' )
{
space ++;
}
else if ( ch > '0' && ch < '9' )
{
num ++;
}
else
{
others ++;
}
}
printf ( "space:%d num:%d letter:%d others:%d",space,num,letter,others );
}
为什么输如一串后,按了回车,光标还是一直闪,不输出个数呢??
本帖最后由 ~风介~ 于 2015-10-29 21:19 编辑
- #include <stdio.h>
- int main ()
- {
- char ch;
- int space, num, others, letter;
-
- printf ( "please input:" );
-
- space = 0;
- num = 0;
- others = 0;
- letter = 0;
- while((ch = getchar())!='\n'){
- if ( ch >= 'a' && ch <= 'z')
- {
- letter ++;
- }
- else if ( ch == ' ' )
- {
- space ++;
- }
- else if ( ch > '0' && ch < '9' )
- {
- num ++;
- }
- else
- {
- others ++;
- }
- }
- printf ( "space:%d num:%d letter:%d others:%d",space,num,letter,others );
-
- }
- /*代码给你改了下,原理二楼有说,你判断时应该是>=和<=,a和z也是字母啊。。。*/
复制代码
|
-
|