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.
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#:
Console.WriteLine(“Depend //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 if (inputString[i]==‘a’ || inputString[i]==‘e’ || inputString[i] == ‘i’ || inputString[i] == ‘o’ || inputString[i] == ‘u’) { vCount++; } //examine and improve the counter if character is consonant else if (inputString[i]>=‘a’ && inputString[i] <= ‘z’) { cCount++; } } //Exhibiting the Vowels and Constants rely in a string to the person Console.WriteLine(“Complete Console.WriteLine(“Complete Console.ReadLine(); |
Preview:
I hope it will enable you in your interview preparation.
Thanks