Group
C# Basic Data Types Overview
Objective
Write a C# program to ask the user for three letters and display them in reverse order.
Example C# Exercise
Show C# Code
using System;
class Program
{
static void Main()
{
// Ask the user for three letters
Console.Write("Enter the first letter: ");
char letter1 = Console.ReadKey().KeyChar;
Console.WriteLine(); // Move to the next line
Console.Write("Enter the second letter: ");
char letter2 = Console.ReadKey().KeyChar;
Console.WriteLine(); // Move to the next line
Console.Write("Enter the third letter: ");
char letter3 = Console.ReadKey().KeyChar;
Console.WriteLine(); // Move to the next line
// Display the letters in reverse order
Console.WriteLine("\nReversed order: " + letter3 + letter2 + letter1);
}
}
Output
//Example 1:
Enter the first letter: A
Enter the second letter: B
Enter the third letter: C
Reversed order: CBA
//Example 2:
Enter the first letter: x
Enter the second letter: y
Enter the third letter: z
Reversed order: zyx