using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Tamaño de la matriz: ");
int cantidad = int.Parse(Console.ReadLine());
int[,] Valores = new int [cantidad+1,cantidad+1];
int[] MaxHorizontal = new int[cantidad + 1];
int[] MaxVertical = new int[cantidad + 1];
// Generamos los valores de la matriz
Random rnd = new Random();
for (int i = 1; i <= cantidad; i++) {
for (int j = 1; j <= cantidad; j++) {
Valores[i, j] = rnd.Next(0, 100);
Console.SetCursorPosition(j * 4, i + 1);
Console.Write(Valores[i, j]);
}
}
// Buscamos el valor máximo por cada fila en horizontal y vertical
for (int i = 1; i <= cantidad; i++) {
MaxHorizontal[i] = Valores[i, 1];
MaxVertical[i] = Valores[i, 1];
for (int j = 1; j <= cantidad; j++) {
if (Valores[i, j] > MaxHorizontal[i])
MaxHorizontal[i] = Valores[i, j];
if (Valores[j, i] > MaxVertical[i])
MaxVertical[i] = Valores[j, i];
}
}
// Mostramos la salida
for (int i = 1; i <= cantidad; i++) {
Console.SetCursorPosition(cantidad*4+10, i + 1);
Console.Write(MaxHorizontal[i]);
}
Console.WriteLine();
for (int i = 1; i <= cantidad; i++) {
Console.SetCursorPosition(i * 4, cantidad + 4);
Console.Write(MaxVertical[i]);
}
Console.WriteLine();
}
}
}
Comentarios sobre la versión: 1 (0)
No hay comentarios