Answer the question
In order to leave comments, you need to log in
Create a 2D array, populate it and randomly select a row and column and delete. To do this, a new array is created. C# I don't understand the error?
Write a program that creates and initializes a two-dimensional numeric array.
Then a row and a column are removed from this array (a new array is created in which one row and one column are removed compared to the original one). The index of the deleted row and the index of the managed row are determined using a random number generator. Here is my code:
int a, b;
int value = 1;
Console.Write("Введите кол-во строк ");
a = Int32.Parse(Console.ReadLine());
Console.Write("Введите кол-во столбцов ");
b = Int32.Parse(Console.ReadLine());
Random rnd = new Random();
int[,] numbs = new int[a, b];
int row = rnd.Next(numbs.GetLength8(0)+1);
int col = rnd.Next(numbs.GetLength(1)+1);
for (int i = 0;i<a;i++)
{
for (int j = 0; j < b; j++)
{
numbs[i, j] = value;
Console.Write(numbs[i, j] + " ");
value++;
}
Console.WriteLine();
}
Console.WriteLine("Удаляются столбец {0} и строка {1} ", col, row);
int v, q;
int[,] tvt = new int[(a - 1), (b - 1)];
for (int i = 0; i < numbs.GetLength(0); i++)
{
if (i < row) v = i;
else v = (i - 1);
for (int j = 0; j < numbs.GetLength(1); j++)
{
if (j < col) q = j;
else q = (j - 1);
}
}
numbs = tvt;
Console.WriteLine();
for (int i = 0; i < numbs.GetLength(0); i++)
{
for (int j = 0; j< numbs.GetLength(1); j++)
{
Console.Write(numbs[i,j] + " ");
}
Console.WriteLine();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question