Program to count number of Vowels (a,e,i,o,u) and consonants in a String in C
Language : C
Similar posts on various String Operations :
- Count number of Words in a String
- Finding String Length in C
- Sorting a String
- File Handling – Reading Strings and individual Characters
[sourcecode language='c']
//count nos. of Vowels and consonants and Whitespaces
#include
#include
int main()
{ char str[50];
int i,count,countc,whitespace;
count=0;countc=0,whitespace=0;
printf(“Enter a string : “);
gets(str);
count=0; i=0;
while(str[i]!=’\0′)
{ if(str[i]==’A’ || str[i]==’a')
count++;
if(str[i]==’E’ || str[i]==’e')
count++;
if(str[i]==’I’ || str[i]==’i')
count++;
if(str[i]==’o’ || str[i]==’O')
count++;
if(str[i]==’ ‘)
whitespace++;
else
countc++;
i++;
}
printf(“The total nos of vowels %d consonants %d and whitespaces %d”,count, countc, whitespace);
getch();
return 0;
}
[/sourcecode]






