Objective
Write a C# program to ask the user for 5 numbers, store them in an array and show them in reverse order.
Write Your C# Exercise
C# Exercise Example
using System; // Import the System namespace for basic functionality
class Program // Define the main class
{
static void Main() // The entry point of the program
{
int[] numbers = new int[5]; // Create an array of 5 integers to store the numbers entered by the user
// Ask the user to enter 5 numbers and store them in the array
for (int i = 0; i < 5; i++)
{
Console.Write($"Enter number {i + 1}: "); // Prompt the user for a number
numbers[i] = Convert.ToInt32(Console.ReadLine()); // Convert the input to an integer and store it in the array
}
// Display the numbers in reverse order
Console.WriteLine("\nNumbers in reverse order:");
for (int i = 4; i >= 0; i--)
{
Console.WriteLine(numbers[i]); // Print each number starting from the last element in the array
}
}
}
Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.
In this C# exercise, you are asked to write a program that checks if a given data belongs to a previously created list. The steps to follow are:
In this C# exercise, you are asked to write a program that asks the user for 10 integer numbers and displays the even ones. This exercise w...
In this C# exercise, you are asked to write a program that asks the user for 10 real numbers and displays the average of the positive ones and the average of t...
In this C# exercise, you are asked to write a program that asks the user for several numbers (until they enter the word "end") and then displays the sum of the...
In this C# exercise, you are asked to write a program that asks the user for marks for 20 pupils (2 groups of 10, using a two-dimensional array), and then disp...
In this C# exercise, you are asked to create a statistical program that allows the user to perform the following actions: - Add new data - See all data ...