Te recomiendo hacer las cosas por ti mismo. Pero igual te ayudo para asi practico yo tambien.
Aca te dejo el problema 1, bastante facilon.
static void Ejercicio1()
{
Random r = new Random();
Dictionary<int, int> coincidences = new Dictionary<int, int>();
Dictionary<int, int> compares = new Dictionary<int, int>();
int minN = 0;
int maxN = 40;
int maxAttemps = 1000;
for(int i = 0; i <= maxAttemps; i++)
{
int rGen = r.Next(minN, maxN);
if(coincidences.ContainsKey(rGen))
{
coincidences[rGen]++;
}
else
{
coincidences[rGen] = 1;
}
}
var order = from pair in coincidences orderby pair.Value descending select pair;
var items = order.Take(6);
int j = 0;
foreach(KeyValuePair<int, int> item in items)
{
if (j > 0)
Console.Write(", ");
Console.Write(item.Key);
j++;
}
}
Aca te dejo el ejercicio 2, vago.
static void Ejercicio2(int[,] m)
{
if(m.Length != 23 * 23)
{
Console.WriteLine("Bad matriz ;)");
}
else
{
for (int x = 0; x < 23; x++)
{
for (int y = 0; y < 23; y++)
{
int v = m[x,y];
if(v % 3 == 0)
{
Console.WriteLine("En la posicion " + x + "," + y + " se ha encontrado el multiplo de 3");
m[x,y] = 33;
}
}
}
}
for (int x = 0; x < 23; x++)
{
for (int y = 0; y < 23; y++)
{
Console.WriteLine("[" + x + "][" + y + "] = " + m[x,y]);
}
}
}
static int[,] generateRandomM()
{
Random r = new Random();
int[,] result = new int[23,23];
for(int x = 0; x < 23; x++)
{
for(int y = 0; y < 23; y++)
{
int rg = r.Next(0, 20);
result[x,y] = rg;
}
}
return result;
}