Exercise
Function Parameters Of Main, Reverse
Objective
Write a C# program named "reverse", which receives several words in the command line and displays them in reverse order, as in this example:
reverse one two three
three two one
Write Your C# Exercise
C# Exercise Example
// Importing the System namespace to access basic system functions
using System;
class Program
{
// Main method where the program starts
public static void Main(string[] args)
{
// Check if there are any arguments passed from the command line
if (args.Length == 0)
{
Console.WriteLine("No words provided."); // If no words are provided, print a message
return; // Exit the program
}
// Loop through the arguments in reverse order and print each word
for (int i = args.Length - 1; i >= 0; i--)
{
Console.Write(args[i] + " "); // Print each word followed by a space
}
Console.WriteLine(); // Add a new line at the end
}
}