Write a program in C# to identify whether a character entered by a user is a vowel or a consonant.
Sample Solution
C# Sharp Code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { char Alphabet; Console.WriteLine("Enter Alphabet A-Z Or a-z"); Alphabet = Convert.ToChar(Console.ReadLine()); switch (Alphabet) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': Console.WriteLine("The Alphabet you have entered is vowal"); break; default: Console.WriteLine("The Alphabet you have entered is consonant "); break; } Console.ReadLine(); } } }
Sample Output
Another Example
C# Sharp Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class alphabet
{
static void Main(string[] args)
{
char ch;
Console.Write("\n\n");
Console.Write("check whether the input alphabet is a vowel or consonant.:\n");
Console.Write("-----------------------------------------------------");
Console.Write("\n\n");
Console.Write("Input an Alphabet (A-Z or a-z) : ");
ch = Convert.ToChar(Console.ReadLine().ToLower());
int i = ch;
if (i >= 48 && i <= 57)
{
Console.Write("You entered a number, Please enter an
alpahbet.");
}
else
{
switch (ch)
{
case 'a':
Console.WriteLine("The Alphabet is vowel");
break;
case 'i':
Console.WriteLine("The Alphabet is vowel");
break;
case 'o':
Console.WriteLine("The Alphabet is vowel");
break;
case 'u':
Console.WriteLine("The Alphabet is vowel");
break;
case 'e':
Console.WriteLine("The Alphabet is vowel");
break;
default:
Console.WriteLine("The Alphabet is Consonant");
break;
}
}
Console.ReadKey();
}
}
Sample Output
If you enter Number then output will be change.
No comments:
Post a Comment