Write a C#.Net application to display the vowels from a given string.

Answer:

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

namespace StringVowels
{
    class Program
    {
        static void Main(string[] args)
        {// Accept a string from the user
            Console.WriteLine("Enter a string: ");
            string input = Console.ReadLine();

            // Call the function to display vowels
            DisplayVowels(input);
        }

        // Function to display vowels from the given string
        static void DisplayVowels(string str)
        {
            // Convert the string to lowercase to handle both uppercase and lowercase vowels
            str = str.ToLower();

            Console.WriteLine("Vowels in the string are: ");

            // Loop through the string and check for vowels
            foreach (char c in str)
            {
                if ("aeiou".Contains(c))
                {
                    Console.Write(c + " ");
                }
            }

            Console.WriteLine(); // To move to the next line after displaying vowels
            Console.ReadLine();
        }
    }
}
Scroll to Top