Form1.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. namespace Лаб9
  11. {
  12. public partial class FArray : Form
  13. {
  14. public FArray()
  15. {
  16. InitializeComponent();
  17. }
  18. private void btnStart_Click(object sender, EventArgs e)
  19. {
  20. dataGridArray.ColumnCount = 20;
  21. dataGridArray.RowCount = 20;
  22. int[,] a = new int[20,20];
  23. int i,j;
  24. int top, bottom, left, right;
  25. Random rand = new Random();
  26. for (i=0;i<20; i++)
  27. for (j=0;j<20;j++)
  28. a[i,j] = rand.Next(-50,50);
  29. for (i=0;i<20;i++)
  30. for (j=0;j<20;j++)
  31. dataGridArray.Rows[i].Cells[j].Value = a[i,j].ToString();
  32. for (i=0;i<20;i++)
  33. {
  34. for (j = 0; j < 20; j++)
  35. {
  36. if (i != 0)
  37. {
  38. top = int.Parse(dataGridArray.Rows[i - 1].Cells[j].Value.ToString());
  39. } else
  40. {
  41. top = -100;
  42. }
  43. if (i != 19)
  44. {
  45. bottom = int.Parse(dataGridArray.Rows[i + 1].Cells[j].Value.ToString());
  46. } else
  47. {
  48. bottom = -100;
  49. }
  50. if (j != 0)
  51. {
  52. left = int.Parse(dataGridArray.Rows[i].Cells[j - 1].Value.ToString());
  53. } else
  54. {
  55. left = -100;
  56. }
  57. if (j != 19)
  58. {
  59. right = int.Parse(dataGridArray.Rows[i].Cells[j + 1].Value.ToString());
  60. }else
  61. {
  62. right = -100;
  63. }
  64. int n = int.Parse(dataGridArray.Rows[i].Cells[j].Value.ToString());
  65. if ((top == -100 || n > top) && (bottom == -100 || n > bottom) && (left == -100 || n > left) && (right == -100 || n > right))
  66. {
  67. dataGridArray.Rows[i].Cells[j].Style.BackColor = Color.Pink;
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }