C Program to Check Vowels Consonant Digits or Space

In this c program:

  • The user is prompted to enter a character.
  • The program checks whether the character is an alphabet, digit, or space.
  • If the character is an alphabet, it further checks whether it is a vowel or a consonant.
  • The result is then printed based on the type of character.

You can run this program, enter a character, and it will tell you whether it’s a vowel, consonant, digit, or space.

Program :

#include<stdio.h>
#include<conio.h>
int main()
{
char str[100];
int i,vowels,consonants,digits,spaces;
vowels=consonants=digits=spaces=0;
printf(“Enter the String : “);
fgets(str,99,stdin);
for(i=0;str[i]!=’\0′;++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’)
{
    printf(“\n %c is a Vowels.”,str[i]);
vowels++;
}
else if((str[i]>=’a’&&str[i]<=’z’)||(str[i]>=’A’&&str[i]<=’Z’))
{
printf(“\n %c is a Consonants.”,str[i]);
consonants++;
}
else if(str[i]>=’0’&&str[i]<=’9′)
{
printf(“\n %c is a Digit.”,str[i]);
digits++;
}
else if(str[i]==’ ‘||str[i]<=’\t’)
{
spaces++;
}
}
printf(“\nNumber of Vowels : %d.”,vowels);
printf(“\nNumber of Consonant : %d.”,consonants);
printf(“\nNumber of Digits : %d.”,digits);
printf(“\nNumber of White space & Tabs : %d.”,spaces);
return 0;
}

Output :

Leave a Comment

Your email address will not be published.

8 thoughts on “C Program to Check Vowels Consonant Digits or Space”

Shopping Basket
Verified by MonsterInsights