Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Language Examples - Determine Vowel or Consonant

C Language Examples - Determine Vowel or Consonant

C Language Examples C Language Examples

Determine whether the entered letter is a vowel or a consonant.

English has 26 letters. The vowels are only a, e, i, o, and u; all the others are consonants. y is a semi-vowel and semi-consonant letter, but in English it is treated as a consonant.

Example

#include

<

stdio.h

int

main

(

)

{

char

c

;

int

isLowercaseVowel

,

isUppercaseVowel

;

printf

(

"

Enter a letter:

"

)

;

scanf

(

"

%c

"

,&

c

)

;

// Lowercase vowel

isLowercaseVowel

=

(

c

== '

a

' ||

c

== '

e

' ||

c

== '

i

' ||

c

== '

o

' ||

c

== '

u

'

)

;

// Uppercase vowel

isUppercaseVowel

=

(

c

== '

A

' ||

c

== '

E

' ||

c

== '

I

' ||

c

== '

O

' ||

c

== '

U

'

)

;

// if statement check

if

(

isLowercaseVowel

||

isUppercaseVowel

)

printf

(

"

%c is a vowel

"

,

c

)

;

else

printf

(

"

%c is a consonant

"

,

c

)

;

return

0

;

}

Running result:



输入一个字母: G

G 是辅音

C Language Examples C Language Examples