/*
* 34.cpp
*
* Created on: 2011-8-8
* Author: san
*/
# include <stdio.h>
int main(void)
{
//定义变量
char c;
int letters = 0;
int space = 0;
int digit = 0;
int others = 0;
//输入
printf("请输入:\n");
while ((c = getchar()) != '\n')
{
if (c>='a' && c<='z' || c>='A' && c<='Z')//统计字符
letters++;
else if (c == ' ')//统计空格
space++;
else if (c >= '0' && c<= '9')//统计数字
digit++;
else //统计别的
others++;
}
//输出
printf("char=%d space=%d digit=%d others=%d", letters, space, digit, others);
return 0;
}
/*
* 在eclipse中输出:
* 请输入:
* 1 2 3 4 5 a b c d e !
* char=5 space=10 digit=5 others=1
*
*/
* 34.cpp
*
* Created on: 2011-8-8
* Author: san
*/
# include <stdio.h>
int main(void)
{
//定义变量
char c;
int letters = 0;
int space = 0;
int digit = 0;
int others = 0;
//输入
printf("请输入:\n");
while ((c = getchar()) != '\n')
{
if (c>='a' && c<='z' || c>='A' && c<='Z')//统计字符
letters++;
else if (c == ' ')//统计空格
space++;
else if (c >= '0' && c<= '9')//统计数字
digit++;
else //统计别的
others++;
}
//输出
printf("char=%d space=%d digit=%d others=%d", letters, space, digit, others);
return 0;
}
/*
* 在eclipse中输出:
* 请输入:
* 1 2 3 4 5 a b c d e !
* char=5 space=10 digit=5 others=1
*
*/