Advertisement
Guest User

Es

a guest
Jul 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApp15
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         Random gen = new Random();
  21.         int[] a = new int[5];
  22.         int[] b = new int[5];
  23.         int[,] m = new int[5, 5];
  24.         private void Button1_Click(object sender, EventArgs e)
  25.         {
  26.             dataGridView1.RowCount = 5;
  27.             dataGridView1.ColumnCount = 5;
  28.  
  29.             for (int i = 0; i < 5; i++)
  30.             {
  31.                 a[i] = gen.Next(0, 10);
  32.                 b[i] = gen.Next(0, 10);
  33.             }
  34.  
  35.             for (int i = 0; i < m.GetLength(0); i++)
  36.                 for (int j = 0; j < m.GetLength(1); j++)
  37.                 {
  38.                     m[i, j] = gen.Next(0, 20);
  39.                     dataGridView1.Rows[i].Cells[j].Value = m[i, j];
  40.                 }
  41.  
  42.             label1.Text = Convert.ToString(MinMax(m, ref a, ref b));
  43.         }
  44.  
  45.         public int MinMax(int[,] m, ref int[] a, ref int[] b)
  46.         {
  47.             int min = 0;
  48.             int y = 0;
  49.             int max = 0;
  50.  
  51.             for (int i = 0; i < m.GetLength(0); i++)
  52.             {
  53.                 min = m[0, 0]; //7
  54.                 for (int j = 1; j < m.GetLength(1); j++)
  55.                 {
  56.                     if (m[0, j] < min)
  57.                     {
  58.                         y = j;
  59.                         min = m[0, j];
  60.                     }
  61.                 }
  62.             }
  63.  
  64.             for (int i = 0; i < m.GetLength(0); i++)
  65.             {
  66.                 max = m[i, y];
  67.  
  68.                 for (int j = 1; j < m.GetLength(1); j++)
  69.                 {
  70.                     if (max < m[j, y])
  71.                         max = m[j, y];
  72.                 }
  73.             }
  74.  
  75.             return max;
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement