Group
C# Arrays, Structures and Strings
Objective
1. Declare an array to store 5 integers.
2. Prompt the user to enter 5 numbers and store them in the array.
3. After all numbers have been entered, iterate over the array in reverse order to display them.
4. Ensure the output clearly shows the reversed order of the numbers.
Write a C# program to ask the user for 5 numbers, store them in an array, and show them in reverse order.
Example C# Exercise
Show C# Code
using System;
class Program
{
static void Main()
{
// Declare an array to store 5 numbers
int[] numbers = new int[5];
// Prompt user to enter 5 numbers
Console.WriteLine("Enter 5 numbers:");
for (int i = 0; i < 5; i++)
{
Console.Write($"Number {i + 1}: ");
numbers[i] = Convert.ToInt32(Console.ReadLine());
}
// Display the numbers in reverse order
Console.WriteLine("\nNumbers in reverse order:");
for (int i = 4; i >= 0; i--)
{
Console.WriteLine(numbers[i]);
}
}
}
Output
// Example Enter 5 numbers:
Number 1: 10
Number 2: 20
Number 3: 30
Number 4: 40
Number 5: 50
Numbers in reverse order:
50
40
30
20
10