其他分享
首页 > 其他分享> > 统计英文字母和数字字符

统计英文字母和数字字符

作者:互联网

本题要求编写程序,输入10个字符,统计其中英文字母、数字字符和其他字符的个数。

输入格式:

输入为10个字符。最后一个回车表示输入结束,不算在内。

输出格式:

在一行内按照

letter = 英文字母个数, digit = 数字字符个数, other = 其他字符个数

的格式输出。请注意,等号的左右各有一个空格,逗号后有一个空格。

输入样例1:

Reold 123?



结尾无空行

输出样例1:

letter = 5, digit = 3, other = 2



结尾无空行

输入样例2:

aZ &
09 Az结尾无空行

输出样例2:

letter = 4, digit = 2, other = 4



结尾无空行

answer

#include <stdio.h>
int main(){
	char ch;
	int letter = 0,digit = 0,other = 0;
	for(int i = 0;i < 10;i++) {
		scanf("%c",&ch);
		if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
			letter++;
		else if(ch >= '0' && ch <= '9')
			digit++;
		else
		 other++;
	}
	printf("letter = %d, digit = %d, other = %d",letter,digit,other);
	return 0;
}

标签:空行,字符,digit,ch,数字,英文字母,样例,other,letter
来源: https://www.cnblogs.com/ekertree/p/15390615.html