Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Feltolt(int[,] t, Random r)
- {
- /* for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- t[i, j] = r.Next(10, 100);
- }
- } */
- t[0, 0] = r.Next(10, 100);
- int x = 0;
- int y = 1;
- while (x < 5)
- {
- int n=r.Next(10,100);
- if (!Vane(t, n, x, y))
- {
- t[x, y] = n;
- y++;
- if (y == 10)
- {
- y = 0;
- x++;
- }
- }
- }
- }
- static bool Vane(int[,] t, int k,int x, int y)
- {
- int i = 0;
- int j = 0;
- bool keres = true;
- bool talal= false;
- while (keres)
- {
- if (k == t[i, j])
- {
- keres = false;
- talal = true;
- }
- else
- {
- j++;
- if (j == 10)
- {
- j = 0;
- i++;
- }
- if ((i == x) && (j == y))
- {
- keres = false;
- }
- }
- }
- return talal;
- }
- static void Kiir(int[,] t, bool l)
- {
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- Console.Write("{0,3}", t[i, j]);
- }
- if (l)
- {
- Console.Write(" | {0}. sor Min: {1} Max:{2} Avg:{3}", i + 1, Min(t, i), Max(t, i), Avg(t, i));
- }
- Console.WriteLine();
- }
- Console.WriteLine();
- }
- static int Min(int[,] t, int sor)
- {
- int min =0;
- for (int j = 1; j < 10; j++)
- {
- if (t[sor, min] > t[sor, j])
- {
- min = j;
- }
- }
- return t[sor, min];
- }
- static int Max(int[,] t, int sor)
- {
- int max = 0;
- for (int j = 1; j < 10; j++)
- {
- if (t[sor, max] < t[sor, j])
- {
- max = j;
- }
- }
- return t[sor, max];
- }
- static double Avg(int[,] t, int sor)
- {
- int sum = 0;
- for (int j = 0; j < 10; j++)
- {
- sum += t[sor, j];
- }
- return (double) sum / 10;
- }
- static void Rendez(int[,] t)
- {
- for (int i = 0; i < 5; i++)
- {
- for (int x = 0; x < 10 - 1; x++)
- {
- int min = x;
- for (int y = x + 1; y < 10; y++)
- {
- if (t[i, min] > t[i, y])
- {
- min = y;
- }
- }
- if (min != x)
- {
- int temp = t[i, min];
- t[i, min] = t[i, x];
- t[i, x] = temp;
- }
- }
- }
- }
- static void Main(string[] args)
- {
- int[,] t = new int[5, 10];
- Random r = new Random();
- Feltolt(t, r);
- Kiir(t,true);
- Rendez(t);
- Kiir(t,false);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement