原本可以按照遞增排序,但只要多宣告下面那個新的陣列就整個跑掉,請問原因?
int[] arr = new int[20];
Random r = new Random();
int count;
for (int count1 = 0; count1 <= 19; count1++)
{
for (count = 0; count <= 19; count++)
{
arr[count] = r.Next(1, 21);
}
Array.Sort(arr);
Console.Write(arr[count1]);
Console.Write(" ");
if (count1 % 5 == 4)
Console.WriteLine();
}
int[] NewArr = new int[20];
Console.Read();
我看不懂,
你新的陣列沒有做任何事啊,
跑掉什麼?
我倒是覺得你前面寫得有點奇怪...
我猜你要的是這樣吧...
int[] arr = new int[20];
Random r = new Random();
int count;
for (count = 0; count <= 19; count++)
arr[count] = r.Next(1, 21);
Array.Sort(arr);
for (count = 0; count <= 19; count++)
{
Console.Write(arr[count]);
Console.Write(" ");
if (count % 5 == 4)
Console.WriteLine();
}