题目描述
输入一个字符串,统计其中元音字母的个数。要求使用函数vowel()用来判断是否为元音,其余功能在main()函数中实现。
int vowel(char ch)
{
//如果ch是元音,返回1,否则返回0
}
本题如果是C/C++代码提交,只需要提交vowel函数的定义部分,提交其它内容,编译出错。
输入
输入一个字符串,长度不超过1000,以回车符结束。
输出
输出一个整数,表示元音字母个数。输出单独占一行。
样例输入
Hello world!
样例输出
3
代码:
#include <stdio.h>
int vowel(char ch){
switch(ch){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': return 1;
default: return 0;
}
}
int main(){
char ch;
int i=0,num=0;
while((ch=getchar())!='\n'&&i<=1000){ //用getchar()判断是否要结束
if(vowel(ch)) num++;
}
printf("%d",num);
}
运行结果:
笔者水平有限,不到之处,还望诸位批评指正。