C++ Program to Check Whether an Alphabet is Vowel or Consonant Using switch-case (Vowel या Consonant की जाँच)

This C++ program checks whether a given alphabet is a vowel or a consonant using the if statement and switch-case statement.

यह C++ प्रोग्राम if तथा switch-case स्टेटमेंट की सहायता से दिए गए alphabet के vowel या consonant होने की जाँच करता है।

Program:

#include <iostream>
using namespace std;
int main()
{
char ch;
cout << "Enter an alphabet: ";
cin >> ch;
// Check whether the input is an alphabet
if ((ch >= 'A' && ch <= 'Z') ||
(ch >= 'a' && ch <= 'z'))
{
switch (ch)
{
case 'A':
case 'a':
case 'E':
case 'e':
case 'I':
case 'i':
case 'O':
case 'o':
case 'U':
case 'u':
cout << ch << " is Vowel" << endl;
break;
default:
cout << ch << " is Consonant" << endl;
}
}
else
{
cout << "Not an Alphabet" << endl;
}
return 0;
}

Output 1:

Enter an alphabet: A
A is Vowel

Output 2:

Enter an alphabet: b
b is Consonant

Output 3:

Enter an alphabet: 5
Not an Alphabet

Explanation (व्याख्या)

First, the if statement checks whether the entered character is an alphabet.

  • If the character is an alphabet, the switch statement checks whether it is one of the vowels: A, E, I, O, U or their lowercase forms.

  • If a vowel case matches, the program displays is Vowel.

  • If none of the vowel cases match, the default block displays is Consonant.

  • If the input is not an alphabet, the program displays Not an Alphabet.

सबसे पहले if स्टेटमेंट यह check करता है कि input character alphabet है या नहीं।

  • यदि character alphabet है, तो switch स्टेटमेंट यह check करता है कि वह vowel (A, E, I, O, U) या उनके lowercase forms में से कोई है या नहीं।

  • यदि कोई vowel case match होता है, तो प्रोग्राम is Vowel प्रदर्शित करता है।

  • यदि कोई vowel case match नहीं होता, तो default block is Consonant प्रदर्शित करता है।

  • यदि input alphabet नहीं है, तो प्रोग्राम Not an Alphabet प्रदर्शित करता है।

This program demonstrates how if and switch-case statements can be used together to check whether a given alphabet is a vowel or consonant.

यह प्रोग्राम दर्शाता है कि if तथा switch-case स्टेटमेंट का एक साथ प्रयोग करके दिए गए alphabet के vowel या consonant होने की जाँच की जा सकती है।

Comments

Popular posts from this blog

Important Questions (IMP) of Programming Methodologies and Data structures using C++ with OOP's Concepts

Complete C++ Programming Syllabus - From Basics to Advanced C++ , including OOP and Data Structures and Algorithms

OOP's using CPP Syllabus AND Programming Methodologies and Data Structures Using C++ (NEP 2020)