C 語言實例 - 判斷母音/輔音
判斷輸入的字母是母音,還是輔音。
英語有26個字母,母音只包括 a、e、i、o、u 這五個字母,其餘的都為輔音。y是半母音、半輔音字母,但在英語中都把他當作輔音。
實例
#include <stdio.h>
int main()
{
    char c;
    int isLowercaseVowel, isUppercaseVowel;
    printf("輸入一個字母: ");
    scanf("%c",&c);
    // 小寫字母母音
    isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
    // 大寫字母母音
    isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
    // if 語句判斷
    if (isLowercaseVowel || isUppercaseVowel)
        printf("%c  是母音", c);
    else
        printf("%c 是輔音", c);
    return 0;
}
運行結果:
輸入一個字母: G G 是輔音

 C 語言實例