在线编译器 C

#include <stdio.h> #include <string.h> int main() { char s[201]; scanf("%s",s); int count=0; int len=strlen(s); for(int i=0;i<len;i++){ char c=s[i]; if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='y'){ count++; } } printf("%d\n",count); return 0; }
这段代码的功能是:读取一个字符串,然后统计其中元音字母(a, e, i, o, u, y)出现的次数,并输出这个次数。

- 代码中把字母 'y' 也当作元音处理了,请确认题目是否要求包含 'y'。
- 如果输入字符串中包含大写字母,当前代码不会将其识别为元音,因为比较的都是小写字母。