C#: Check a input is a vowel, a digit, or any other symbol
Write a C# Sharp program that takes a character as input and checks if it is a vowel, a digit, or any other symbol.
Sample Solution:-
C# Sharp Code:
using System;
public class Exercise9
{
public static void Main()
{
// Declare a variable to store the symbol entered by the user
char symbol;
// Input a symbol from the user
Console.Write("Input a symbol: ");
symbol = Convert.ToChar(Console.ReadLine());
// Check if the entered symbol is a lowercase vowel
if ((symbol == 'a') || (symbol == 'e') || (symbol == 'i') ||
(symbol == 'o') || (symbol == 'u'))
{
Console.WriteLine("It's a lowercase vowel.");
}
// Check if the entered symbol is a digit
else if ((symbol >= '0') && (symbol <= '9'))
{
Console.WriteLine("It's a digit.");
}
// If the entered symbol doesn't match the above conditions, it's another symbol
else
{
Console.Write("It's another symbol.");
}
}
}
Sample Output:
Input a symbol: a It's a lowercase vowel.
Visual Presentation:
Flowchart:
![Flowchart: Check a input is a vowel, a digit, or any other symbol.](https://www.w3resource.com/w3r_images/csharp-datatype-exercise-flowchart-9.png)
C# Sharp Practice online:
Contribute your code and comments through Disqus.
Previous: Write a C# Sharp program that takes the radius of a sphere as input and calculate and display the surface and volume of the sphere.
Next: Write a C# Sharp program that takes two numbers as input and returns true or false when both numbers are even or odd.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics