C program to count total number of vowel or consonant in a string using switch case and pointer. / C प्रोग्राम स्विच केस और पॉइंटर का उपयोग करके एक स्ट्रिंग में स्वर या व्यंजन की कुल संख्या की गणना करने के लिए।












C program to count total number of vowel or consonant in a string using switch case and pointer.




C program to count total number of vowel or consonant in a string using switch case and pointer.



#include <stdio.h> #include <string.h> #define MAX 100 int main() { char text[MAX]; char * s = text; int vowel, consonant; printf("\n Enter any string: "); gets(text); vowel = 0; consonant = 0; while(*s) { if((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <='Z')) { switch(*s) { case 'a': case 'e': case 'i': case 'o': case 'u': case 'A': case 'E': case 'I': case 'O': case 'U': vowel++; break; default: consonant++; } } s++; } printf("\n Number of vowel in the enter string = %d", vowel); printf("\n Number of consonant in the enter string = %d", consonant); return 0; }


Output:
Enter any string: computer Number of vowel in the enter string = 3 Number of consonant in the enter string = 5





Exercise: 1
C program to count total number of vowels and consonants in a string.