Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp15
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- Random gen = new Random();
- int[] a = new int[5];
- int[] b = new int[5];
- int[,] m = new int[5, 5];
- private void Button1_Click(object sender, EventArgs e)
- {
- dataGridView1.RowCount = 5;
- dataGridView1.ColumnCount = 5;
- for (int i = 0; i < 5; i++)
- {
- a[i] = gen.Next(0, 10);
- b[i] = gen.Next(0, 10);
- }
- for (int i = 0; i < m.GetLength(0); i++)
- for (int j = 0; j < m.GetLength(1); j++)
- {
- m[i, j] = gen.Next(0, 20);
- dataGridView1.Rows[i].Cells[j].Value = m[i, j];
- }
- label1.Text = Convert.ToString(MinMax(m, ref a, ref b));
- }
- public int MinMax(int[,] m, ref int[] a, ref int[] b)
- {
- int min = 0;
- int y = 0;
- int max = 0;
- for (int i = 0; i < m.GetLength(0); i++)
- {
- min = m[0, 0]; //7
- for (int j = 1; j < m.GetLength(1); j++)
- {
- if (m[0, j] < min)
- {
- y = j;
- min = m[0, j];
- }
- }
- }
- for (int i = 0; i < m.GetLength(0); i++)
- {
- max = m[i, y];
- for (int j = 1; j < m.GetLength(1); j++)
- {
- if (max < m[j, y])
- max = m[j, y];
- }
- }
- return max;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement