C Programming
Computer Programming

C program to Find the number of vowels consonants digits and white spaces



Write a program in C to Find the number of vowels, consonants, digits and white spaces

\* C program to Find the number of vowels consonants digits and white spaces *\

# include < stdio.h >
# include < conio.h >
int   main( )
{

char line[150] ;
int i, vowels, consonants, digits, spaces ;
vowels = consonants = digits = spaces = 0 ;
printf("\n Enter a line of string: ") ;
scanf( "%[^\n]", line ) ;
for( i=0; line[i]!='\0'; ++i )
{
      if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
      line[i]=='o' || line[i]=='u' || line[i]=='A' ||
      line[i]=='E' || line[i]=='I' || line[i]=='O' ||
      line[i]=='U')
      {
            ++vowels ;
      }
      else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
      {
            ++consonants ;
      }
      else if( line[i]>='0' && line[i]<='9' )
      {
            ++digits ;
      }
      else if ( line[i]==' ' )
      {
            ++spaces ;
      }
}
printf("\n Vowels: %d", vowels ) ;
printf("\n Consonants: %d", consonants ) ;
printf("\n Digits: %d",digits ) ;
printf("\n White spaces: %d", spaces ) ;
return 0 ;

}

Output of Program :

Output of C program to Find the number of vowels consonants digits and white spaces