Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active May 16, 2023 16:47
Show Gist options
  • Select an option

  • Save Strelok78/0706ea6ed7fd1d2a983cffa5bc5d7523 to your computer and use it in GitHub Desktop.

Select an option

Save Strelok78/0706ea6ed7fd1d2a983cffa5bc5d7523 to your computer and use it in GitHub Desktop.
Finds the greatest element of the matrix A(10,10) and writes zero to the cells where it is located. Outputs the greatest element, the original and the resulting matrix.
{
internal class Program
{
static void Main(string[] args)
{
int[,] a = new int[10, 10];
int maxInTable = int.MinValue;
int minValue = 1;
int maxValue = 100;
Random random = new Random();
for (int i = 0; i < a.GetLength(0); i++)
{
for (int j = 0; j < a.GetLength(1); j++)
{
a[i, j] = random.Next(minValue, maxValue);
maxInTable = maxInTable > a[i, j] ? maxInTable : a[i, j];
Console.Write(a[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
for (int i = 0; i < a.GetLength(0); i++)
{
for (int j = 0; j < a.GetLength(1); j++)
{
if (a[i, j] == maxInTable)
{
a[i, j] = 0;
}
Console.Write(a[i, j] + " ");
}
Console.WriteLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment