Last active
April 29, 2025 11:03
-
-
Save Strelok78/89829ff5039f7415c658346006a70761 to your computer and use it in GitHub Desktop.
get max value in two dimensional array and replace with zero
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Diagnostics; | |
using System.Text; | |
namespace iJuniorPractice; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int[,] numbers = | |
{ | |
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, | |
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, | |
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, | |
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, | |
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, | |
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, | |
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, | |
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, | |
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, | |
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } | |
}; | |
int maxValue = int.MinValue; | |
int valueReplacer = 0; | |
int rowDimensionLength = numbers.GetLength(0); | |
int columnDimensionLength = numbers.GetLength(1); | |
Console.WriteLine("Original array:"); | |
for (int i = 0; i < rowDimensionLength; i++) | |
{ | |
for (int j = 0; j < columnDimensionLength; j++) | |
{ | |
maxValue = Math.Max(maxValue, numbers[i,j]); | |
Console.Write(numbers[i,j] + " "); | |
} | |
Console.WriteLine(); | |
} | |
Console.WriteLine("\nUpdated array:"); | |
for (int i = 0; i < rowDimensionLength; i++) | |
{ | |
for (int j = 0; j < columnDimensionLength; j++) | |
{ | |
if(maxValue == numbers[i,j]) | |
{ | |
numbers[i,j] = valueReplacer; | |
} | |
Console.Write(numbers[i,j] + " "); | |
} | |
Console.WriteLine(); | |
} | |
Console.WriteLine($"\nMax value = {maxValue}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment