Write a program in C#.Net to read n numbers in an array and display them in reverse order.

Answer:

using System;

namespace ReverseArray
{
    class Program
    {
        static void Main(string[] args)
        {// Prompt the user to enter the number of elements
            Console.WriteLine("Enter the number of elements:");
            int n = int.Parse(Console.ReadLine());  // Read the number of elements

            // Declare an array to store the numbers
            int[] numbers = new int[n];

            // Read the numbers from the user
            Console.WriteLine("Enter " + n + " numbers:");

            for (int i = 0; i < n; i++)
            {
                Console.Write("Enter number: ");
                numbers[i] = int.Parse(Console.ReadLine());  // Store each number in the array
            }

            // Display the numbers in reverse order
            Console.WriteLine("\nThe numbers in reverse order are:");
            for (int i = n - 1; i >= 0; i--)
            {
                Console.WriteLine(numbers[i]);  // Print the numbers in reverse order
            }
            Console.ReadLine();
        }
    }
}
Scroll to Top