Q:

C program to check whether a character is vowel or consonant

0

C program to check whether a character is vowel or consonant

C program to check whether a character is a vowel or consonant: A user inputs a character, and we check whether it's a vowel or not. Both lower-case and upper-case are checked.

If a character isn't a vowel, it doesn't mean it's a consonant because it might be a digit or a special symbol

C program to check vowel or consonant using if else

In this program, we check whether a character is a vowel or consonant or punctuation or a symbol.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
int main()
{
  char ch;

  printf("Input a character\n");
  scanf("%c", &ch);

  if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' &&ch <= 'Z')) {
    if (ch=='a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch== 'u' || ch=='U')
      printf("%c is a vowel.\n", ch);
    else
      printf("%c is a consonant.\n", ch);
  }
  else
    printf("%c is neither a vowel nor a consonant.\n", ch);

  return 0;
}

output:

Input a character

s

s is a consonant.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now