Design wrapper classes about program in C# to read n number of values in an array and display it in reverse order. thank you in advance
using System;
namespace Questions
{
class Program
{
class Array
{
private int n;
private double[] values;
public Array(int n)
{
this.n = n;
values = new double[n];
}
public void InputValues()
{
for(int i = 0; i < n; i++)
{
Console.Write(string.Format("Enter number #{0}: ",i+1));
values[i] = double.Parse(Console.ReadLine());
}
}
public void PrintInReverseOrder()
{
for (int i = n - 1; i >= 0; i--)
Console.Write(values[i] + " ");
}
}
static void Main()
{
Console.Write("n = ");
int n = int.Parse(Console.ReadLine());
Array array = new Array(n);
array.InputValues();
Console.WriteLine();
Console.Write("Reverse order: ");
array.PrintInReverseOrder();
Console.WriteLine();
Console.ReadKey();
}
}
}
Comments
Leave a comment