设计一个程序,求5*6的二维数组中元素的最大值和最小值~~!!!

2024-10-27 23:43:27
推荐回答(1个)
回答1:

//随即产生了一个5X6的矩阵,所有元素∈[0,100]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CONSOLE
{
class Program
{
static void Main(string[] args)
{
int [,] numbers=new int[5,6];
int x, y;
int max,min;
Random ra=new Random();
for (x = 0; x <= 4; x++)
{
for (y = 0; y <= 5; y++)
{
numbers[x, y] = ra.Next(100);
Console.Write("{0}, ", numbers[x, y]);
}
Console.Write("\n");
}
max = numbers[0, 0];
min = numbers[0, 0];
for (x = 0; x <= 4; x++)
for (y = 0; y <= 5; y++)
{
if (numbers[x,y]>max)
max = numbers[x, y];
if (numbers[x,y] min = numbers[x, y];
}
Console.WriteLine("Max={0}, Min={1}", max, min);
Console.ReadKey();
}
}
}