Удаление элементов массива относительно главной диагонали - C#
Формулировка задачи:
Доброго времени суток дорогие форумчани.
Вот такая задача стоит у меня:
При запуске программы она моментально выключается. Где я допустил ошибку, помогите пожалуйста.
Код программы:
Листинг программы
- 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 WindowsFormsApplication4
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- static object[,] array;
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void buttonForm_Click(object sender, EventArgs e)
- {
- try
- {
- dataGridView1.RowCount = int.Parse(textBox1.Text);
- dataGridView1.ColumnCount = int.Parse(textBox1.Text);
- array = new object[dataGridView1.RowCount, dataGridView1.ColumnCount];
- dataGridView1.Visible = true;
- buttonRez.Visible = true;
- for (int i = 0; i < dataGridView1.RowCount; i++)
- {
- for (int j = 0; j < dataGridView1.ColumnCount; j++)
- {
- if (i % 2 == 0) array[i, j] = 1;
- else array[i, j] = 0;
- }
- }
- for (int i = 0; i < dataGridView1.RowCount; ++i)
- for (int j = 0; j < dataGridView1.ColumnCount; ++j)
- dataGridView1.Rows[i].Cells[j].Value = array[i, j];
- buttonRez.Enabled = true;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- }
- private void buttonRez_Click(object sender, EventArgs e)
- {
- try
- {
- dataGridView2.ColumnCount = 0;
- dataGridView2.RowCount = int.Parse(textBox1.Text);
- dataGridView2.ColumnCount = int.Parse(textBox1.Text);
- dataGridView2.Visible = true;
- for (int i = 0; i < dataGridView2.RowCount; i++)
- {
- for (int j = i + 1; j < dataGridView2.ColumnCount; j++)
- {
- if (((int)array[i, j]) == 0) array[i, j] = " ";
- }
- }
- for (int i = 1; i < dataGridView2.RowCount; i++)
- {
- for (int j = 0; j < i; j++)
- {
- if ((int)array[i, j] == 1) array[i, j] = " ";
- }
- }
- for (int i = 0; i < dataGridView2.RowCount; ++i)
- for (int j = 0; j < dataGridView2.ColumnCount; ++j)
- dataGridView2.Rows[i].Cells[j].Value = array[i, j];
- buttonRez.Enabled = false;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void label2_Click(object sender, EventArgs e)
- {
- }
- private void button3_Click(object sender, EventArgs e)
- {
- }
- private void label3_Click(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void buttonForm_Click_1(object sender, EventArgs e)
- {
- }
- }
- }
Решение задачи: «Удаление элементов массива относительно главной диагонали»
textual
Листинг программы
- Application.Run(new Form1());
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д