✅ Extracting max number from 2D array?
Code is below
I have no idea why it shows as -5 instead of 12?
using System;
namespace Coding.Exercise
{
public class Exercise
{
public static int FindMax(int[,] numbers)
{
int max = 0;
var height = numbers.GetLength(0);
if(height == 0){
return -1;
}
var width = numbers.GetLength(1);
if(width == 0){
return -1;
}
for(int i = 0; i < height; i++){
for(int j = 0; j < width; j++){
if(numbers[i,j] < max){
max = numbers[i,j];
}
}
}
return max;
}
}
}using System;
namespace Coding.Exercise
{
public class Exercise
{
public static int FindMax(int[,] numbers)
{
int max = 0;
var height = numbers.GetLength(0);
if(height == 0){
return -1;
}
var width = numbers.GetLength(1);
if(width == 0){
return -1;
}
for(int i = 0; i < height; i++){
for(int j = 0; j < width; j++){
if(numbers[i,j] < max){
max = numbers[i,j];
}
}
}
return max;
}
}
}I have no idea why it shows as -5 instead of 12?
