India Languages, asked by ShrutiBagartti176, 1 year ago

Conditional statement to check whether input alphabet is vowel

Answers

Answered by benjai10vignesp78mcd
0

Answer:

Explanation:

#include <stdio.h>

int main()

{

   char c;

   int isLowercaseVowel, isUppercaseVowel;

   printf("Enter an alphabet: ");

   scanf("%c",&c);

   // evaluates to 1 (true) if c is a lowercase vowel

   isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

   // evaluates to 1 (true) if c is an uppercase vowel

   isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

   // evaluates to 1 (true) if either isLowercaseVowel or isUppercaseVowel is true

   if (isLowercaseVowel || isUppercaseVowel)

       printf("%c is a vowel.", c);

   else

       printf("%c is a consonant.", c);

   return 0;

}

OR

#include <stdio.h>

#include <ctype.h>

int main()

{

   char c;

   int isLowercaseVowel, isUppercaseVowel;

   do {

       printf("Enter an alphabet: ");

       scanf(" %c", &c);

   }

   // isalpha() returns 0 if the passed character is not an alphabet

   while (!isalpha(c));

   // evaluates to 1 (true) if c is a lowercase vowel

   isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

   // evaluates to 1 (true) if c is an uppercase vowel

   isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

   // evaluates to 1 (true) if either isLowercaseVowel or isUppercaseVowel is true

   if (isLowercaseVowel || isUppercaseVowel)

       printf("%c is a vowel.", c);

   else

       printf("%c is a consonant.", c);

   return 0;

}

Similar questions