C program to count total number of vowel or consonant in a string using for loop.
C program to count total number of vowel or consonant in a string using for loop.
#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; i='a' && text[i]<='z') || (texti]>='A' && text[i]<='Z'))
{
if(text[i] =='a' || text[i]=='e' || text[i]=='i' ||
text[i]=='o' || text[i]=='u' || text[i] =='A' ||
text[i]=='E' || text[i]=='I' || text[i]=='O' || texti]=='U' )
vowel++;
else
consonant++;
}
}
printf("\n Total number of vowel in the string = %d", vowel);
printf("\n Total number of consonant in the string = %d", consonant);
return 0;
}
Output:
Enter any string: computer
Total number of vowel in the string = 3
Total number of consonant in the string = 5