C# program to count vowels in a string

Write a C# program to count vowels in a string

C# program to count vowels in a string

Object:

Write C# a program that contains a class that has a method that takes user name as input and second functions which returns the number of vowels present in it and the Main program prints the number of vowels, C# program to count vowels in a string.C# Projects with Source Code

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lab_3b
{
     class name
{
              public void name()
              {
                   string name;
                    Console.WriteLine(“Please Enter Your Name and Check how many vowels present in your Name. “);
                    name = Console.ReadLine();
                    vow(name);
               }
               void vow(string n)
               {
                    int vol=0, len = n.Length;
                    for (int k = 0; k<len; k++)
                     {
                         if (n[k] == ‘a’ || n[k] == ‘e’ || n[k] == ‘i’ || n[k] == ‘o’ || n[k] == ‘u’ || n[k] == ‘A’ || n[k] == ‘E’ || n[k] == ‘O’ || n[k] == ‘U’)
                        {
                             vol++;
                        }
                    }
                   Console.WriteLine(“\n\nNumber of Vowels in this name: {0}”, vol);
               }
     }

     class Program
     {
          static void Main()
         {
              names i = new names();
              i.nam();
              Console.ReadKey();
         }
     }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lab_3b
{
    class names
    {
        public void nam()
        {
            string name;
            Console.WriteLine("Please Enter Your Name and Check how many vowels present in your Name. ");
            name = Console.ReadLine();
            vow(name);
        }
        void vow(string n)
        {
            int vol=0, len = n.Length;
            for (int k = 0; k<len; k++)
            {
                if (n[k] == 'a' || n[k] == 'e' || n[k] == 'i' || n[k] == 'o' || n[k] == 'u' || n[k] == 'A' || n[k] == 'E' || n[k] == 'O' || n[k] == 'U')
                {
                    vol++;
                }
            }
            Console.WriteLine("\n\nNumber of Vowels in this name: {0}", vol);
        }
    }
           
    class Program
    {
        static void Main()
        {
            names i = new names();
            i.nam();
            Console.ReadKey();
        }
    }
}

Output:

C# program to count vowels in a string

Another C# Program: C# Program Calculating the Area of a Rectangle

Another C# Program: C# Program that Subtracts two user-defined numbers

Another C# Program: C# Program Create a class student with a data members name and calculate marks and percentage.

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

2 Responses

  1. December 26, 2020

    […] C# program to count vowels in a string […]

  2. January 31, 2021

    […] C# program to count vowels in a string […]

Leave a Reply

Your email address will not be published. Required fields are marked *