Está en la página 1de 3

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
class Program
{

static Random x = new Random();

static void Main(string[] args)


{

int i = 0, n = 0;
Console.Write("Ingrese el tama�o de la matriz : ");
n = Convert.ToInt16(Console.ReadLine());
int[,] A = new int[n, n];

llenar(ref A);
mostrar(ref A, 5);
menosserepite(ref A);
masserepite(ref A);

Console.ReadKey();

static void llenar(ref int[,] aux)


{
int i = 0, j = 0, k = 0;
while (i < aux.GetLength(0))
{
k = 0;
while (k < aux.GetLength(1))
{
j = x.Next(1, 20);
aux[i, k] = j;
k++;
}
i++;
}
}

static void mostrar(ref int[,] aux, int coordenada)


{
int i = 0, j = 0;
while (i < aux.GetLength(0))
{

j = 0;
while (j < aux.GetLength(1))
{
Console.SetCursorPosition(20 + (j * 3), i + 3);
Console.WriteLine(aux[i, j]);
j++;
}
i++;
}
}
static void menosserepite(ref int[,] aux)
{

int i = 0, j = 0;

int contador = 0;

i = 0;

int M;

M = aux[0, 0];

while (i < aux.GetLength(0))


{
while (j < aux.GetLength(1))
{

if (M > aux[i, j])

{
M = aux[i, j];
contador++;
}

j++;
}

j = 0;

i++;
}

Console.ReadLine();

Console.SetCursorPosition(3, 30);
Console.WriteLine("El numero que menos se repite es {0}", contador);

Console.ReadKey();

}
static void masserepite(ref int[,] aux)
{
int i = 0;
int j =0;
int contador = 0, x;

//Console.SetCursorPosition(3, 25);
//Console.Write("Ingrese el numero a buscar ==> ");
//x = Convert.ToInt32(Console.ReadLine());
int M = 0;
M = aux[0, 0];

while (i < aux.GetLength(0))


{
while (j < aux.GetLength(1))
{
if (M== aux[i, j])
{
contador++;
}

j++;
}

j = 0;

i++;
}

i = 0;
j = 0;

Console.SetCursorPosition(3, 27);
Console.Write("El numero {0}, es el que mas se repite se repite ==> {0}
", M,contador);

}
}
}

También podría gustarte