Learn how to use logical operators and conditional statements to check if a character is a vowel or consonant.
To write a C/C++ program that takes a character as input from the user and checks whether it is a vowel or a consonant.
In English, there are 5 vowels and 21 consonants:
In this practical, you will write a program that:
|| (OR) operator to check multiple conditions. For example, ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'.
Run the program:
Sample Input & Output:
| Type | Letters | Count |
|---|---|---|
| Vowels | A, E, I, O, U (and a, e, i, o, u) | 5 |
| Consonants | B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Y, Z | 21 |
| Total Letters | A - Z | 26 |
|| operator is used to check multiple vowel conditions.
You have successfully written a C program that checks whether a character is a vowel or a consonant. You have learned how to use logical operators (||) and conditional statements to make decisions based on character input.
|| operator checks if at least one condition is true. If any of the vowel conditions is true, the character is a vowel.
tolower() or toupper() functions from the ctype.h library to convert the character to lowercase or uppercase before checking, making the code shorter.
ایک C/C++ پروگرام لکھنا جو صارف سے ایک حرف ان پٹ کے طور پر لے اور چیک کرے کہ آیا یہ حرفِ علت ہے یا حرفِ صحیح۔
انگریزی میں 5 حروفِ علت اور 21 حروفِ صحیح ہیں:
اس عملی میں، آپ ایک پروگرام لکھیں گے جو:
|| (OR) آپریٹر استعمال کریں۔ مثال کے طور پر، ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'۔
پروگرام چلائیں:
نمونہ ان پٹ اور آؤٹ پٹ:
| قسم | حروف | تعداد |
|---|---|---|
| حروفِ علت (Vowels) | A, E, I, O, U (اور a, e, i, o, u) | 5 |
| حروفِ صحیح (Consonants) | B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Y, Z | 21 |
| کل حروف | A - Z | 26 |
|| آپریٹر کا استعمال متعدد حروفِ علت کی شرائط کو چیک کرنے کے لیے کیا جاتا ہے۔
آپ نے کامیابی سے ایک C پروگرام لکھا ہے جو چیک کرتا ہے کہ آیا کوئی حرف حرفِ علت ہے یا حرفِ صحیح۔ آپ نے سیکھ لیا ہے کہ کس طرح منطقی آپریٹرز (||) اور مشروط بیانات کا استعمال کرتے ہوئے حروف کی بنیاد پر فیصلے کیے جاتے ہیں۔
|| آپریٹر چیک کرتا ہے کہ آیا کم از کم ایک شرط درست ہے۔ اگر حروفِ علت کی کوئی بھی شرط درست ہے تو حرف حرفِ علت ہے۔
ctype.h لائبریری سے tolower() یا toupper() فنکشنز کا استعمال کر سکتے ہیں تاکہ حرف کو چیک کرنے سے پہلے چھوٹے یا بڑے حروف میں تبدیل کیا جا سکے، جس سے کوڈ چھوٹا ہو جاتا ہے۔