Найти наибольшее из чисел x, y, z, где x – след матрицы А, y – след матрицы В, z – след матрицы С - C#
Формулировка задачи:
Всем привет) Нужна помощь! Не могу оформить метод. Помогите пожалуйста
Даны матрицы А(3, 3), В(4, 4) и С(5, 5). Найти наибольшее из чисел x, y, z, где x – след матрицы А, y – след матрицы В, z – след матрицы С. Вычисление следа матрицы(сумма элементов главной диагонали) оформить в виде метода.
Решение задачи: «Найти наибольшее из чисел x, y, z, где x – след матрицы А, y – след матрицы В, z – след матрицы С»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static Random rnd = new Random();
public static int Sled(int[,] array2d)
{
int sum = 0;
for (int i = 0; i < array2d.GetLength(0); i++)
sum += array2d[i, i];
return sum;
}
public static int[,] Generate(int n)
{
int[,] array2d = new int[n, n];
for (int i = 0; i < array2d.GetLength(0); i++)
for (int j = 0; j < array2d.GetLength(1); j++)
array2d[i, j] = rnd.Next(-10,11);
return array2d;
}
static void Main(string[] args)
{
int[,] A = Generate(3);
int[,] B = Generate(4);
int[,] C = Generate(5);
int x = Sled(A);
int y = Sled(B);
int z = Sled(C);
int maximum = Math.Max(x, Math.Max(y, z));
Console.WriteLine(maximum);
Console.ReadKey(true);
}
}
}