Untitled

Run Settings
LanguageC#
Language Version
Run Command
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Arrays.Net { class Program { static void Main(string[] args) { Random r = new Random(); int[] a = new int [20]; for (int i = 0; i < a.Length; i++) { a[i] = r.Next(-10, 11); Console.Write($"{a[i]}, "); } Console.WriteLine( "\nSorting:"); Array.Sort(a); ArrayPrint(a); Console.WriteLine("\n Binary search of '5':"); Console.WriteLine(Array.BinarySearch(a, 5)); Array.Clear(a, 10, 5); ArrayPrint(a); int[] b = new int[50]; //Array.Copy(a, 0, b, 7, 10); Array.Copy(a, b, 20); //a.CopyTo(b, 20); ArrayPrint(b); a = b; ArrayPrint(a); // Linear (sequential) search Console.WriteLine($"\nIndexOf(10): {Array.IndexOf(a, 0,Array.IndexOf(a, 0, Array.IndexOf(a, 0, Array.IndexOf(a, 0)+1) + 1) +1)}"); int[,] c = new int[5, 4]; Console.WriteLine(c.Rank); // Number of dimensions for (int row = 0; row < c.GetLength(0); row++) // Loop for rows for (int column = 0; column < c.GetLength(1); column++) // Loop for columns c[row, column] = r.Next(0, 21); // Filling the 2D array elements ArrayPrint(c); //Array.Sort(c); // Doesn't work with multidimensional arrays int[] temp = new int[c.Length]; int k = 0; foreach (int item in c) temp[k++] = item; Array.Sort(temp); k = 0; for (int row = 0; row < c.GetLength(0); row++) for (int column = 0; column < c.GetLength(1); column++) c[row, column] = temp[k++]; ArrayPrint(c); } private static void ArrayPrint(int[] a) { Console.WriteLine("---------------------------------------\n"); foreach (var item in a) Console.Write($"{item}, "); Console.WriteLine(); } private static void ArrayPrint(int[,] c) { Console.WriteLine("---------------------------------------\n"); for (int i = 0; i < c.GetLength(0); i++) { for (int j = 0; j < c.GetLength(1); j++) { Console.Write($"{c[i, j]}\t"); } Console.WriteLine(); } Console.WriteLine(); } } }
Editor Settings
Theme
Key bindings
Full width
Lines