Check Character is Vowel or Consonant in c

C language में एक ऐसा program लिखिए जो user से एक character input ले और बताए कि दिया गया character:

  • Vowel (स्वर) है
  • Consonant (व्यंजन) है
  • या फिर Invalid input है (alphabet नहीं है)

किसी भी programming language को सीखने के लिए Practice बहोत जरुरी है, इस लिये आज हम समझेंगे Check Character is Vowel or Consonant in c program.

 Program Code

#include <stdio.h>

int main()
{
    char ch;
    printf("Enter Character : ");
    scanf("%c", &ch);

    if (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z')
    {
        if (ch == 'a' || ch == 'i' || ch == 'e' || ch == 'o' || ch == 'u' ||
            ch == 'A' || ch == 'I' || ch == 'E' || ch == 'O' || ch == 'U')
        {
            printf("Entered character is a Vowel.");
        }
        else
        {
            printf("Entered character is a Consonant.");
        }
    }
    else
    {
        printf("\nInvalid input! Enter an alphabet only.");
    }
    return 0;
}

Output:

Enter Character : a

Entered character is a Vowel.

Program Logic

1.  Header File

यह header file printf() और scanf() जैसे input-output functions के लिए जरूरी है।

2️. Variable Declaration

यहाँ char type का variable बनाया गया है क्योंकि हमें single character input लेना है।

3️. Character Input

User से एक character input लिया गया है और ch variable में store किया गया।

4️. Alphabet Check

यह condition check करती है कि input alphabet है या नहीं

  • ‘A’ से ‘Z’ → Capital letters
  • ‘a’ से ‘z’ → Small letters

अगर character alphabet नहीं है, तो program सीधे Invalid input दिखाता है।

5️. Vowel Check

यह condition check करती है कि character vowel है या नहीं।
Capital और small दोनों vowels को check किया गया है।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top