C#: Check a input is a vowel, a digit, or any other symbol
C# Sharp Basic Data Types: Exercise-9 with Solution
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:
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.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/csharp-exercises/data-types/csharp-data-type-exercise-9.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics