Удаление элементов массива относительно главной диагонали - C#

Узнай цену своей работы

Формулировка задачи:

Доброго времени суток дорогие форумчани. Вот такая задача стоит у меня: При запуске программы она моментально выключается. Где я допустил ошибку, помогите пожалуйста. Код программы:
Листинг программы
  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 WindowsFormsApplication4
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. static object[,] array;
  19.  
  20. private void label1_Click(object sender, EventArgs e)
  21. {
  22. }
  23. private void buttonForm_Click(object sender, EventArgs e)
  24. {
  25. try
  26. {
  27. dataGridView1.RowCount = int.Parse(textBox1.Text);
  28. dataGridView1.ColumnCount = int.Parse(textBox1.Text);
  29. array = new object[dataGridView1.RowCount, dataGridView1.ColumnCount];
  30. dataGridView1.Visible = true;
  31. buttonRez.Visible = true;
  32. for (int i = 0; i < dataGridView1.RowCount; i++)
  33. {
  34. for (int j = 0; j < dataGridView1.ColumnCount; j++)
  35. {
  36. if (i % 2 == 0) array[i, j] = 1;
  37. else array[i, j] = 0;
  38. }
  39. }
  40. for (int i = 0; i < dataGridView1.RowCount; ++i)
  41. for (int j = 0; j < dataGridView1.ColumnCount; ++j)
  42. dataGridView1.Rows[i].Cells[j].Value = array[i, j];
  43. buttonRez.Enabled = true;
  44. }
  45.  
  46. catch (Exception ex)
  47. {
  48. MessageBox.Show(ex.Message);
  49. }
  50. }
  51. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  52. {
  53. }
  54. private void buttonRez_Click(object sender, EventArgs e)
  55. {
  56. try
  57. {
  58. dataGridView2.ColumnCount = 0;
  59. dataGridView2.RowCount = int.Parse(textBox1.Text);
  60. dataGridView2.ColumnCount = int.Parse(textBox1.Text);
  61. dataGridView2.Visible = true;
  62. for (int i = 0; i < dataGridView2.RowCount; i++)
  63. {
  64. for (int j = i + 1; j < dataGridView2.ColumnCount; j++)
  65. {
  66. if (((int)array[i, j]) == 0) array[i, j] = " ";
  67. }
  68. }
  69. for (int i = 1; i < dataGridView2.RowCount; i++)
  70. {
  71. for (int j = 0; j < i; j++)
  72. {
  73. if ((int)array[i, j] == 1) array[i, j] = " ";
  74. }
  75. }
  76. for (int i = 0; i < dataGridView2.RowCount; ++i)
  77. for (int j = 0; j < dataGridView2.ColumnCount; ++j)
  78. dataGridView2.Rows[i].Cells[j].Value = array[i, j];
  79. buttonRez.Enabled = false;
  80. }
  81. catch (Exception ex)
  82. {
  83. MessageBox.Show(ex.Message);
  84. }
  85. }
  86.  
  87. private void label2_Click(object sender, EventArgs e)
  88. {
  89. }
  90. private void button3_Click(object sender, EventArgs e)
  91. {
  92. }
  93. private void label3_Click(object sender, EventArgs e)
  94. {
  95. }
  96. private void textBox1_TextChanged(object sender, EventArgs e)
  97. {
  98. }
  99. private void Form1_Load(object sender, EventArgs e)
  100. {
  101. }
  102. private void buttonForm_Click_1(object sender, EventArgs e)
  103. {
  104. }
  105. }
  106. }

Решение задачи: «Удаление элементов массива относительно главной диагонали»

textual
Листинг программы
  1. Application.Run(new Form1());

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

5   голосов , оценка 4.2 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы