.NET Practical Slip 28 Q A

Answer:

Source Code

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();
        }
    }
}

Helpful Links

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top