1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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 Лаб9
- {
- public partial class FArray : Form
- {
- public FArray()
- {
- InitializeComponent();
- }
- private void btnStart_Click(object sender, EventArgs e)
- {
- dataGridArray.ColumnCount = 20;
- dataGridArray.RowCount = 20;
- int[,] a = new int[20,20];
- int i,j;
- int top, bottom, left, right;
- Random rand = new Random();
- for (i=0;i<20; i++)
- for (j=0;j<20;j++)
- a[i,j] = rand.Next(-50,50);
- for (i=0;i<20;i++)
- for (j=0;j<20;j++)
- dataGridArray.Rows[i].Cells[j].Value = a[i,j].ToString();
-
- for (i=0;i<20;i++)
- {
- for (j = 0; j < 20; j++)
- {
- if (i != 0)
- {
- top = int.Parse(dataGridArray.Rows[i - 1].Cells[j].Value.ToString());
- } else
- {
- top = -100;
- }
- if (i != 19)
- {
- bottom = int.Parse(dataGridArray.Rows[i + 1].Cells[j].Value.ToString());
- } else
- {
- bottom = -100;
- }
- if (j != 0)
- {
- left = int.Parse(dataGridArray.Rows[i].Cells[j - 1].Value.ToString());
- } else
- {
- left = -100;
- }
- if (j != 19)
- {
- right = int.Parse(dataGridArray.Rows[i].Cells[j + 1].Value.ToString());
- }else
- {
- right = -100;
- }
- int n = int.Parse(dataGridArray.Rows[i].Cells[j].Value.ToString());
- if ((top == -100 || n > top) && (bottom == -100 || n > bottom) && (left == -100 || n > left) && (right == -100 || n > right))
- {
- dataGridArray.Rows[i].Cells[j].Style.BackColor = Color.Pink;
- }
- }
- }
- }
- }
- }
|