Monday, July 22, 2024
HomeC#Program to Depend Vowels and Consonants in a string ~ IT Tutorials...

Program to Depend Vowels and Consonants in a string ~ IT Tutorials with Instance

One of many well-liked applications which will be requested by the interviewer through the interview is to rely no. of Vowels and Consonants in a string. The letters A, E, I, O, and U are referred to as Vowels and the opposite letters (besides vowels) within the alphabet are often known as Consonants.

I’ll suggest you to examine the beneath hyperlink for Prime C# Interview Packages requested through the Interview and Examination.

Within the beneath instance, Consumer will enter the string which shall be transformed to lowercase in order that comparability will be performed with out worrying about Higher-case or Decrease-case characters. Then looping via every character of the string and examine whether or not the character is in ‘a’, ’e’, ’I’, ’o’, and ‘u’. If sure, then improve the vowel counter worth by 1. If the entered alphabet is between a to z however not in Vowels then want to extend Consonants variable worth by 1. 

Program in C#:

no. of Vowels and Consonants in a string”

//Variables to carry the Vowels and Consonants rely

int vCount = 0;

int cCount = 0;

string inputString = string.Empty;

//Recieve the enter from the person

inputString = Console.ReadLine();

//Decrease the characters of the string for the comparision

inputString = inputString.ToLower();

//Loop via the every character of the string

for (int i = 0; i < inputString.Size; i++)


    //examine and improve
the counter if character is vowel

    if (inputString[i]==‘a’ || inputString[i]==‘e’ || inputString[i] == ‘i’ || inputString[i] == ‘o’ || inputString[i] == ‘u’)




    //examine and improve the counter if character is consonant

    else if (inputString[i]>=‘a’ && inputString[i] <= ‘z’)





//Exhibiting the Vowels and Constants rely in a string to the person

no. of Vowels in a string=”
+ vCount);

no. of Constants in a string=”
+ cCount);



I hope it will enable you in your interview preparation.




Please enter your comment!
Please enter your name here

Most Popular

Recent Comments