0
다차원 배열을 정렬하려고했지만 불행히도 그 작업을 수행 할 수 없었습니다. 사용자가 차원, 요소를 넣고 결과를 내림차순으로 가져올 수있는 정수 배열입니다. 여기 내가 한 일이 있습니다. 감사합니다C#에서 다차원 배열 정렬
는 사이class Program
{
static void Main(string[] args)
{
int rows;
int columbs;
Console.WriteLine("Enter the number of rows");
rows = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the number of columbs");
columbs = int.Parse(Console.ReadLine());
int[,] number = new int[rows, columbs];
Console.WriteLine("Enter the elements of the array");
for (int i = 0; i < rows; i++)
{
for (int y = 0; y < columbs; y++)
{
number[i, y] = int.Parse(Console.ReadLine());
}
}
int a;
int z;
int w;
for (w = 0; w < rows; w++)
{
for (z = 0; z < columbs; z++)
if (number[w, z] < number[w, z++])
{
a = number[w, z++];
number[w, z++] = number[w, z];
number[w, z] = a;
}
}
Console.WriteLine();
foreach (int k in number)
{
Console.WriteLine(k);
}
Console.ReadKey();
}
}
모든 'z ++'가 'z'씩 증가합니다. 나는 당신의 의도가 이것이라고 생각하지 않습니다. 'z + 1'을 사용하십시오. BTW : 그것은 응용 프로그램을 디버깅하는 방법을 배울 적절한시기입니다. –
나는 z + 1을 시도하고 "색인이 배열의 경계를 벗어났습니다."라는 오류가 발생합니다. –
코드에서 유일한 버그가 아니기 때문에 내가 말했듯이, 당신은 항상 당신을 도울 누군가를 찾을 수 없습니다. 디버깅을 배우십시오. –