<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # C 程序:檢查字符是元音還是輔音 > 原文: [https://www.programiz.com/c-programming/examples/vowel-consonant](https://www.programiz.com/c-programming/examples/vowel-consonant) #### 在此示例中,您將學習檢查用戶輸入的字母是元音還是輔音。 要理解此示例,您應該了解以下 [C 編程](/c-programming "C tutorial")主題: * [C 編程運算符](/c-programming/c-operators) * [C `if...else`語句](/c-programming/c-if-else-statement) * [C `while`和`do...while`循環](/c-programming/c-do-while-loops) * * * 五個字母`A`,`E`,`I`,`O`和`U`稱為元音。 除這 5 個元音以外的所有其他字母稱為輔音。 該程序假定用戶將始終輸入字母字符。 * * * ## 檢查元音或輔音的程序 ```c #include <stdio.h> int main() { char c; int lowercase, uppercase; printf("Enter an alphabet: "); scanf("%c", &c); // evaluates to 1 if variable c is lowercase lowercase = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); // evaluates to 1 if variable c is uppercase uppercase = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); // evaluates to 1 if c is either lowercase or uppercase if (lowercase || uppercase) printf("%c is a vowel.", c); else printf("%c is a consonant.", c); return 0; } ``` **輸出** ```c Enter an alphabet: G G is a consonant. ``` * * * 用戶輸入的字符存儲在變量`c`中。 如果`c`是小寫元音,則`lowercase`變量的值為 1(真),而對于其他任何字符,則其值為 0(假)。 同樣,如果`c`是大寫元音,則`uppercase`變量的值為 1(真),而對于其他任何字符,則其值為 0(假)。 如果`lowercase`或`uppercase`變量為 1(真),則輸入的字符為元音。 但是,如果`lowercase`和`uppercase`變量均為 0,則輸入的字符為輔音。 **注意**:該程序假定用戶將輸入字母。 如果用戶輸入非字母字符,則顯示該字符為常數。 要解決此問題,我們可以使用[`isalpha()`](/c-programming/library-function/ctype.h/isalpha "C isalpha() Function")函數。`islapha()`函數檢查字符是否為字母。 ```c #include <stdio.h> #include <ctype.h> int main() { char c; int lowercase, uppercase; printf("Enter an alphabet: "); scanf("%c", &c); // evaluates to 1 if variable c is lowercase lowercase = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); // evaluates to 1 if variable c is uppercase uppercase = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); ? // Show error message if c is not an alphabet if (!isalpha(c)) { printf("Error! Non-alphabetic character."); } ? // if c is an alphabet else { // evaluates to 1 if c is either lowercase or uppercase if (lowercase || uppercase) printf("%c is a vowel.", c); else printf("%c is a consonant.", c); } return 0; } ``` 現在,如果用戶輸入非字母字符,您將看到: ```c Error! Non-alphabetic character. ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看