MATLAB版本:
A = [ 4 6 3 2;
1 5 8 9;
0 4 10 6 ];
max(max(A)) %Maximum value of A
min(min(A)) %Minimum value of A
二楼正解,充分显示了matlab在矩阵运算的高效
C#语言
using System;
namespace andian
{
class Program
{
static void Main(string[] args)
{
int i,j;
int max=0,min=0;
int[,] a = { { 4, 6, -3, 2 }, { 1, -5, 8, 9 }, { 0, 4, 10, 6 } };
Console.WriteLine("矩阵:");
for (i = 0; i < 3; i++)
{
Console.WriteLine();
for (j = 0; j < 4; j++)
{
Console.Write("{0} ", a[i, j]);
if (a[i, j] > max) max = a[i, j];
if (a[i, j] < min) min = a[i, j];
}
}
Console.WriteLine("\n矩阵最大值为:{0}",max);
Console.WriteLine("矩阵最小值为:{0}",min);
Console.ReadLine();
}
}
}