10. 题目:
编写程序统计句子中元音字母(a/e/i/o/u,不分大小写)的个数:
Enter a sentence:And that is the way it is。
Your sentence contains 7 vowels.
c语言实现:
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int count=0;
char ch;
printf("Enter a sentence:");
while (1)
{
ch = getchar();
ch = toupper(ch);
if (ch == '\n')
{
break;
}
switch (ch)
{
case 'A': case 'E': case 'I': case 'O': case 'U':
count += 1;
break;
defult:
break;
}
}
printf("Your sentencd contains %d vowels.\n",count);
return 0;
}