Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 2.08 KB

File metadata and controls

51 lines (38 loc) · 2.08 KB

C 程序:检查字母是元音还是辅音

原文: https://beginnersbook.com/2017/09/c-program-to-check-whether-an-alphabet-is-vowel-or-consonant/

该程序检查输入字符是元音还是辅音。

示例:用于检查元音或辅音的程序

此程序将字符值(由用户输入)作为输入,并使用if-else语句检查该字符是否为元音或辅音。由于允许用户以小写和大写形式输入字母,因此程序检查大写和小写元音和辅音。要理解该程序,您应该熟悉以下 C 编程概念:

  1. C 编程if语句
  2. C 编程if..else语句
#include <stdio.h>
int main()
{
    char ch;
    bool isVowel = false;

    printf("Enter an alphabet: ");
    scanf("%c",&ch);

    if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'
    		||ch=='o'||ch=='O'||ch=='u'||ch=='U')
    {
    	isVowel = true;

    }
    if (isVowel == true)
        printf("%c is a Vowel", ch);
    else
        printf("%c is a Consonant", ch);
    return 0;
}

输出:

Enter an alphabet: E
E is a Vowel

看看这些相关的 C 程序:

  1. C 程序:将小写字符串转换为大写
  2. C 程序:将大写字符串转换为小写
  3. C 程序:查找字符的 ASCII 值
  4. C 程序:在不使用预定义函数的情况下连接两个字符串
  5. C 程序:在不使用strlen 的情况下查找字符串的长度