using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KekTus
{
class Program
{
static void PrintArr(int[][] arr)
{
foreach (var str in arr)
{
foreach (var el in str)
Console.Write($"{el}\t");
Console.WriteLine();
}
}
static void Main(string[] args)
{
int M;
int N;
try
{
Console.Write("M = "); M = int.Parse(Console.ReadLine());
Console.Write("N = "); N = int.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("Ошибка ввода");
return;
}
if (N < 0 || M < 0)
{
Console.WriteLine("Ошбка ввода");
return;
}
Console.WriteLine("M = {0}; N = {1}.", M, N);
int[][] Arr = new int[M][];
var rand = new Random();
for(int i = 0; i < M; ++i)
{
Arr[i] = new int[N];
for (int j = 0; j < N; ++j)
Arr[i][j] = rand.Next(10,99);
}
Console.WriteLine("Исходный массив:");
PrintArr(Arr);
Console.WriteLine();
int[][] Buffer = new int[N][];
for (int j = 0; j < N; ++j)
Buffer[j] = new int[M];
for (int i = 0; i < M; ++i)
for (int j = 0; j < N; ++j)
Buffer[j][i] = Arr[i][j];
Arr = Buffer;
Console.WriteLine("Преобразованный :");
PrintArr(Arr);
Console.WriteLine();
}
}
}
что-то типа этого:
const n = 8, m = 8;
var
A: array[1..n,1..m] of integer;
i, j, sum, product: integer;
isnotnull: boolean;
begin
randomize;
writeln('Случайная матрица:'); for i:=1 to n do begin
for j:=1 to m do begin
A[i,j] := random(51) - 25;
write(A[i,j]:5);
end;
writeln;
end; sum := 0;
for i:=1 to n do
if A[i,n-i+1] < 0 then
sum := sum + A[i,n-i+1];
writeln('Сумма отрицательных элементов побочной диагонали = ', sum); product := 1;
isnotnull := False;
for i:=1 to n-1 do
for j:=2 to n do
if (j > i) and (A[i,j] <> 0) then begin
isnotnull := True;
product := product * A[i,j];
end;
if isnotnull
writeln('Произведение ненулевых элементов в области выше главной диагонали = ', product)
else
writeln('Ненулевых элементов в области выше главной диагонали нет.', product); readln;
end.