In this tutorial you will learn about the C Program to Count Vowels, and Consonants in a String and its application with practical example.
C Program to Count Vowels, and Consonants in a String
In this tutorial, we will learn to create a C program that will Count the Vowels and Consonants in a String in C programming
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- For loop in c programming.
1. Declaring the variables for the program.
2. Taking the input number from the user.
3. Adding the given sting to program.
4. Passing those variables to for loop.
5. Using those numbers to be saved in variables and filter them with for loop.
6. Printing the result words.
Count the Vowels and Consonants in a String
As we all know, the String is a collection of all characters. In strings, only one variable is declared which can store multiple values. First, will take the line of string from the user. Then will filter the number of vowels and the consonants from that strings. At last, we will print the result numbers.
With the help of this program, we can Count the Vowels and Consonants in a String.
/* declaring the required variables for the program */
/* Taking the input string from the user for the program */
printf("Enter the string : ");
/* Filtering the vowels and the consonants from the string */
if((s[i]>=65 && s[i]<=90)|| (s[i]>=97 && s[i]<=122))
if(s[i]=='a'|| s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O' ||s[i]=='U')
/* Printing the number of vowels in that string */
printf("vowels = %d\n",vowels);
/* Printing the number of consonants in that string */
printf("consonants = %d\n",consonants);
In the above program, we have first initialized the required variable.
- s = it will hold the string value.
- Vowels = it will hold the integer value for vowels.
- Consonant = it will hold the integer value for consonants.
- i = it will hold the integer value.
Input strings from the user.
Filtering the vowels and the consonants from the string.
Printing output numbers of the vowels and the consonants.