Wednesday, November 25, 2015

Reads a sentence and prints frequency of each of the vowels and total count of consonants

#include<stdio.h>
#include<conio.h>
int main(){
    char text[100];
    int i,vowel=0,cons=0;
    clrscr();
    printf("Enter a string:\n");
    gets(text);
    for(i=0;text[i]!='\0';++i)
    {
if(text[i]=='a' || text[i]=='e' || text[i]=='i' || text[i]=='o' || text[i]=='u' || text[i]=='A' || text[i]=='E' || text[i]=='I' || text[i]=='O' || text[i]=='U')
{
   ++vowel;
}
else if((text[i]>='a'&& text[i]<='z') || (text[i]>='A'&& text[i]<='Z'))
{
   ++cons;
}
    }
    printf("Vowels: %d",vowel);
    printf("\nConsonants: %d",cons);
    getch();
    return 0;
}

To Compile Press Alt+f9 
To Run Press Ctrl+f9

Output:



No comments:

Post a Comment