C++ 中查詢字元是母音還是子音的程式


在本教程中,我們將討論一個程式,該程式找出某個字元是母音還是子音。

為此,我們會提供一個字元。我們的任務是向用戶輸出所提供的字元是母音還是子音。

示例

 即時演示

#include <iostream>
using namespace std;
//checking if the character is a vowel or consonant
void is_vowel(char x){
   if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u')
      cout << "Vowel" << endl;
   else
      cout << "Consonant" << endl;
}
int main(){
   is_vowel('c');
   is_vowel('e');
   return 0;
}

輸出

Consonant
Vowel

更新時間: 2020 年 5 月 4 日

182 次瀏覽

啟動你的 職業

完成課程即可獲得認證

開始
廣告
© . All rights reserved.