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