Source code:
//Write a C program to count total number of vowel or consonant in a string
#include <stdio.h>
#include <string.h>
int main()
{
char s[1000],ch;
int i=0, vowel, consonant;
printf("Enter your sentence:");
while(ch != '\n') /* terminates if user hit enter */
{
ch = getchar();
s[i] = ch;
i++;
}
s[i-1] = '\0'; /* inserting null character at end */
int len;
vowel = 0;
consonant = 0;
len = strlen(s);
for(i=0; i<len; i++)
{
if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z'))
{
if(s[i] =='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u' ||
s[i] =='A' || s[i]=='E' || s[i]=='I' || s[i]=='O' || s[i]=='U' )
vowel++;
else
consonant++;
}
}
printf("Total number of vowel = %d\n", vowel);
printf("Total number of consonant = %d\n", consonant);
return 0;
}
Output: