using System; class SortDemo { static void Main() { int[] nums = { 1, 2, 3, 4, 5 }; // Display original order. Console.Write("Original order: "); Console.ReadLine(); foreach (int i in nums) Console.Write(i + " "); Console.WriteLine(); // Reverse the entire array. Array.Reverse(nums); // Display reversed order. Console.Write("Reversed order: "); foreach (int i in nums) Console.Write(i + " "); Console.WriteLine(); // Reverse a range. Array.Reverse(nums, 1, 3); // Display reversed order. Console.WriteLine("Range reversed: "); Console.Write("From position 1 to 3 numbers need to be reversed : "); foreach (int i in nums) Console.Write(i + " "); Console.ReadLine(); } }
Monday, 4 February 2019
Reversing an Array Using Build in Function in C#
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment