输入一串字符(长度不超过1000,以回车符结束),统计其中元音字母的个数。输出要求:输入一个整数,表示元音字母个数;输出单独占一行。
/*给的示例需要注意说明:‘A和’a'都是元音.*/
输入:Hello World!
输出:3
#include<stdio.h>#include<math.h>int vowel(char ch);int main(){char ch;int count;count = 0;while ((ch = getchar()) != '\n'){if (vowel(ch) == 1)count++;}printf("%d", count);return 0;}int vowel(char ch){if (ch == 'A' || ch == 'a' || ch == 'E' || ch == 'e' || ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o' || ch == 'U' || ch == 'u')return 1;elsereturn 0;}
此处用到了‘输入一串字符’的方法,刚开始学,感觉有必要记住。