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 alphabetif ((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: AA is Vowel
Output 2:
Enter an alphabet: bb is Consonant
Output 3:
Enter an alphabet: 5Not an Alphabet
Explanation (व्याख्या)
First, the if statement checks whether the entered character is an alphabet.
If the character is an alphabet, the
switchstatement checks whether it is one of the vowels:A,E,I,O,Uor their lowercase forms.If a vowel case matches, the program displays
is Vowel.If none of the vowel cases match, the
defaultblock displaysis 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 नहीं होता, तो
defaultblockis 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
Post a Comment