/*Count Vowel and Consonant in word GOOD MORNING*/
#include <stdio.h>
#include <string.h>
int main()
{
char name[] = "GOOD MORNING";
int i, len, vowelCount = 0, consonantCount = 0;
len = strlen(name);
for(i = 0; i < len; i++)
{
if(name[i] == 'A' || name[i] == 'E' || name[i] == 'I' ||
name[i] == 'O' || name[i] == 'U' || name[i] == 'a' ||
name[i] == 'e' || name[i] == 'i' || name[i] == 'o' ||
name[i] == 'u') {
vowelCount++;
}
else if((name[i] >= 'A' && name[i] <= 'Z') ||
(name[i] >= 'a' && name[i] <= 'z')) {
consonantCount++;
}
}
printf("The number of vowels in the string is: %d\n", vowelCount);
printf("The number of consonants in the string is: %d\n", consonantCount);
return 0;
}
/*Count Vowel and Consonant any text*/
#include <stdio.h>
#include <string.h>
int main()
{
char str[100];
int vowels = 0, consonants = 0;
printf("Enter a string: ");
fgets(str, 100, stdin);
for(int i=0; i<strlen(str); i++)
{
if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' ||
str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U')
{
vowels++;
}
else if((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
{
consonants++;
}
}
printf("Number of vowels: %d\n", vowels);
printf("Number of consonants: %d\n", consonants);
return 0;
}