C Programming

Count number of Vowels and Consonants in a String

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 :

[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]




WordPress - Vaibhav Kanwal