您的位置:首页 > 其它

统计某一句话里面 元音字母的个数

2013-08-23 17:08 330 查看
应用switch 语句,

#include<stdio.h>
int main(void)
{    char ch;
int a_ctl,e_ctl,i_ctl,o_ctl,u_ctl;
a_ctl = e_ctl = i_ctl = o_ctl = u_ctl =0;
printf("        Enter some text,and a # to quit\n"
"        I will tell you the number of the vowel\n"    );
while((ch=getchar()) != '#')
{
switch(ch)
{
case 'A':
case 'a': a_ctl++;break;
case 'E':
case 'e': e_ctl++;break;
case 'I':
case 'i': i_ctl++;break;
case 'O':
case 'o': o_ctl++;break;
case 'U':
case 'u': u_ctl++;break;// 保留此处的break,为了方便以后添加其他选项
default: break;
}

}
printf("number of vowels: \n"
"a:%d    e:%d    i:%d    o:%d    u:%d\n",a_ctl,e_ctl,i_ctl,o_ctl,u_ctl);
return 0;
}


刚开始 把printf放在 while循环里面了,结果就悲剧了·····以后注意哈

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: