Consonant and vowels





Count Consonant and Vowels

            Hello friends, here we are seeing the c program for the count the number of the vowel and consonant in the given string. We know a, e, i, o, u are five vowels. But how we check how many times the vowels and consonant have come in the sentence. So by using the following c program we easily count the number of vowels and consonant in the given string.


C language code for count the consonant and vowel:
#include<stdio.h>
#include<conio.h>
void main()
{
            int c=0,count=0;
            char s[1000];
            int i;
            clrscr();

printf("Enter the string:"); //for take a string from user

gets(s);//this function is use to store the string

    for(i=0;s[i]!='\0';++i); //for accessing each character from the string and count the character

    printf("Length of given string: %d\n", i);//print the no of character including space

while(s[c]!='\0')//string is not null
            {

              if(s[c]=='a' || s[c]=='A' || s[c]=='e'|| s[c]=='E' || s[c]=='i' ||
              s[c]=='I' || s[c]=='o' || s[c]=='O' || s[c]=='u' || s[c]=='U')
              //compares vowels with each and every character

              count++;// for counting the vowels

              c++; //go to next character

            }

            printf("The no of vowels in the given string is:%d\n",count);
            // no of vowels in a given string

            printf("Number of Consonent with spaces in the given string:%d\n",i-count);
            //no of the consonant in the given string

            getch(); //this function holds the output screen
}

Output:
Enter the string: c language
Length of given string:10
The no of vowels in the given string is:4
Number of Consonant with spaces in the given string:6



Consonant and vowels Consonant and vowels Reviewed by Amit Waghmare on August 12, 2019 Rating: 5

No comments: