Wednesday, 10 September 2014

Count Vowels in a string in C Language Program with Example

How to find the vowels count of a given text by using switch in C program?

This C program is used to find the number of vowels in your given text by using a switch statement. Initially checking the character of text separately and match with case value. If the character matches with the condition, then increment by one in the vowel count or ignore the character. Finally print the number of vowels present in the given input text.

Vowels count program in C

//Header files
void main()
      //Program varaibles
    int eCou=0,aCou=0,oCou=0,iCou=0,conCou=0,uCou=0;
    char cha;
    clrscr(); //Function to clear the previous output
    printf("Enter ur text here : \n"); //Display function
    while((cha=getchar())!='\n'//Unconditional statement
        switch(cha) //Switch statement
            case 'a':
                    aCou++; break;
            case 'e':
                    eCou++; break;
            case 'i':
                    iCou++; break;
            case 'o':
                    oCou++; break;
            case 'u':
                    uCou++; break;
    printf("Number of Character \n");
    printf("a\t%d;e\t%d;i\t%d;o\t%d;u\t%d;rest\t%d ;",aCou,eCou,iCou,oCou,uCou,conCou);

No comments:

Post a comment

Note: only a member of this blog may post a comment.