Write a C Program to Check Whether a Character is Vowel or Consonant.

Prince Patel
By -
0

Write a C Program to Check Whether a Character is Vowel or Consonant.



In this Article of programming, the ability to perform simple yet fundamental tasks is crucial. Determining whether a given character is a vowel or a consonant is one such task. In this article, we will delve into the creation of a C program that accomplishes this task without employing user-defined structures or functions.

Vowels and Consonants:

Before we dive into the programming aspect, let's refresh our understanding of vowels and consonants. In the English alphabet, there are five vowels: 'a', 'e', 'i', 'o', and 'u'. The remaining letters are considered consonants. The program we are about to construct will differentiate between these two categories for a given character.

Here's a  C Program to Check Whether a Character is Vowel or Consonant:

#include<stdio.h>
#include<conio.h>
void main()
{

    // Declare a character variable to store user input
    char ch;

    // Prompt the user to enter a character
    printf("Enter a character: ");
    scanf("%c", &ch);

    // Check if the entered character is an uppercase vowel
    if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch== 'U')
    {
        printf("%c is a vowel.\n", ch);
    }
    // Check if the entered character is a lowercase vowel
    else if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
    {
        printf("%c is a vowel.\n", ch);
    }
    // Check if the entered character is an alphabet
    else if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
    {
        printf("%c is a consonant.\n", ch);
    }
    // If the character is not an alphabet
    else
    {
        printf("%c is not an alphabet.\n", ch);
    }
}

  • The program checks if the entered character is an uppercase vowel using a set of if conditions. Similarly, it checks for lowercase vowels and consonants.
  • If the entered character is not an alphabet (i.e., it's a symbol, digit, or whitespace), the program displays that it is not an alphabet.
Output:







Tags:

Post a Comment

0Comments

Post a Comment (0)