Tech Point Fundamentals

Monday, November 29, 2021

C# Program to Find Vowels and Consonants Count in a String

C# Program to Find Vowels and Consonants Count in a String


Most of the IT companies check the coding skills and problem-solving skills as well along with the theoretical interview questions. Sometimes you are free to write the pseudo code and sometimes you are asked to write the complete program either on any paper or any editor. 

This question is asked in the coding interview to write the program. Here you can find the program as well as a live running program so that you can test the program immediately.

Watch our videos here


How can you find the total number of vowels and consonants in a given string? Write a program to find the number of vowels and consonants in a string.

C# Program To Find Vowels and Consonants Count in a String


// Author 	: Tech Point Fundamentals
// Website 	:
// Channel	:
// Demo		: Vowels and Consonants Count in String

using System;

public class Program
 public static void Main()
  string inputString = "Tech Point Fundamentals";		
  int vowelCount,  ConsonentCount;
  VowelsConsonantsCount(inputString, out vowelCount, out ConsonentCount);
  Console.WriteLine("Input String : " + inputString);
  Console.WriteLine("Vowels Counts : " + vowelCount);
  Console.WriteLine("Consonants Counts : " + ConsonentCount);	

public static void VowelsConsonantsCount(string inputString, out int vowelCount, out int ConsonentCount)    
  vowelCount = 0;
  ConsonentCount = 0;		
  char[] charArray = inputString.ToLower().ToCharArray(); 
  foreach(char item in charArray)
  	if(item != ' ')
  	if(item == 'a' || item == 'e' || item == 'i' || item == 'o' || item == 'u')
  		vowelCount = vowelCount + 1;
  		ConsonentCount = ConsonentCount + 1;	


               Input String : Tech Point Fundamentals Vowels Counts : 7 Consonants Counts : 14

Live Demo

No comments:

Post a Comment

Please do not enter any HTML. JavaScript or spam link in the comment box.