C Program to count vowels and consonents in a given sentence
Program
#include<stdio.h>
#include<string.h>
int isVowel(char character)
{
if(character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u' || character == 'A' || character == 'E' || character == 'I' || character == 'O' || character == 'U')
return 1;
else
return 0;
}
void main()
{
char sentence[100];
int i, vowels = 0, consonants = 0, digits = 0, spaces = 0;
printf("Enter a line:\n");
fgets(sentence, 100, stdin);
for(i = 0; sentence[i] != '\n'; i++)
{
if(isVowel(sentence[i]))
{
vowels++;
}
else
{
consonants++;
}
}
printf("Number of vowels:\t%d\n", vowels);
printf("Number of consonants:\t%d\n", consonants);
}
Output
$ gcc c-program-count-vowels-consonants-sentence.c
$ ./a.out
Enter a line:
hello user welcome to oodlescoop
Number of vowels: 13
Number of consonants: 19