Menu Close

C语言练习:给一个字母,检查是元音或是辅音

英语的26个字母分两种类型:一种叫元音字母,另一种叫辅音字母,元音字母有:a,e,i,o,u五个,其余为辅音字母,辅音字母分别b、c、d、f、g、h、j、k、l、m、n、p、q、r、s、t、v、w、x、y、z。

#include <stdio.h>
int main()
{
    char ch;
    int isVowel = 0; //C 语言没有bool类型

    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 = 1;

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

结果:

Enter an alphabet: w
w is a Consonant
除教程外,本网站大部分文章来自互联网,如果有内容冒犯到你,请联系我们删除!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Leave the field below empty!

Posted in C语言习题集

Related Posts