Q. Program to count the total number of vowels and consonants in a string.In this program, our task is to count the total number of vowels and consonants present in the given string. As we know that, The characters a, e, i, o, u are known as vowels in the English alphabet. Any character other than that is known as the consonant. To solve this problem, First of all, we need to convert every upper-case character in the string to lower-case so that the comparisons can be done with the lower-case vowels only not upper-case vowels, i.e.(A, E, I, O, U). Then, we have to traverse the string using a for or while loop and match each character with all the vowels, i.e., a, e, I, o, u. If the match is found, increase the value of count by 1 otherwise continue with the normal flow of the program. The algorithm of the program is given below. Algorithm
ComplexityO(n) SolutionPythonOutput: Number of vowels: 10 Number of consonants: 17 COutput: Number of vowels: 10 Number of consonants: 17 JAVAOutput: Number of vowels: 10 Number of consonants: 17 C#Output: Number of vowels: 10 Number of consonants: 17 PHPOutput: Number of vowels: 10 Number of consonants: 17 Next TopicPrograms List |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India