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












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




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



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