输入一段英文文字,筛选出其中的元音字母及个数。

输入一段英文文字,筛选出其中的元音字母及个数。,第1张

输入一段英文文字,筛选出其中的元音字母及个数。 版本一:switch,case多重标签的代码
#include 

int main(void) {
	int a_ct, e_ct, i_ct, o_ct, u_ct ;
	a_ct = e_ct = i_ct = o_ct = u_ct = 0;
	char ch;
	printf("Enter some text,enter # to quit.n");
	while ((ch = getchar()) != '#') {
		switch (ch) {
			case 'a':
			case 'A':
				a_ct++;
				break;
			case 'e':
			case 'E':
				e_ct++;
				break;
			case 'i':
			case 'I':
				i_ct++;
				break;
			case 'o':
			case 'O':
				o_ct++;
				break;
			case 'u':

			case'U':

				u_ct++;
				break;
			default:
				break;

		}

	}
	printf("Number of vowles:A	E	I	O	Un");
	printf("				 %4d%4d%4d%4d%4dn", a_ct, e_ct, i_ct, o_ct, u_ct);
	return 0;
}
版本二:无多重标签,要用到toupper()函数
#include 
//toupper()函数的库函数
#include 

int main(void) {
	int a_ct, e_ct, i_ct, o_ct, u_ct ;
	a_ct = e_ct = i_ct = o_ct = u_ct = 0;
	char ch;
	printf("Enter some text,enter # to quit.n");
	while ((ch = getchar()) != '#') {
		ch = toupper(ch);
		switch (ch) {

			case 'A':
				a_ct++;
				break;

			case 'E':
				e_ct++;
				break;

			case 'I':
				i_ct++;
				break;

			case 'O':
				o_ct++;
				break;


			case'U':

				u_ct++;
				break;
			default:
				break;

		}

	}
	printf("Number of vowles:A	E	I	O	Un");
	printf("				 %4d%4d%4d%4d%4dn", a_ct, e_ct, i_ct, o_ct, u_ct);
	return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5699579.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存