Привести матрицу к треугольному виду и найти количество строк - C#
Формулировка задачи:
Есть код на программу, которая задает матрицу размера MxN, нужно привести ее к треугольному виду найти количество строк, среднее арифметическое элементов которых меньше заданной величины. Помогите, пожалуйста хотя бы с переводом к треугольному виду.
Код:
Форма программы:
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void textBox3_TextChanged(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- textBox3.Text = "";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- textBox3.Text = "";
- int[,] mas = new int[100, 100];
- int m = Convert.ToInt32(textBox1.Text), n = Convert.ToInt32(textBox2.Text);
- Random a = new Random();
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- mas[i, j] = a.Next(10);
- textBox3.Text = textBox3.Text + Convert.ToString(mas[i, j]) + " ";
- }
- textBox3.Text = textBox3.Text + System.Environment.NewLine;
- }
- int s = 0;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- if (mas[j, i] == 0)
- {
- s++;
- break;
- }
- }
- }
- }
- }
- }
Решение задачи: «Привести матрицу к треугольному виду и найти количество строк»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void textBox3_TextChanged(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- textBox3.Text = "";
- textBox4.Text = "";
- }
- int[,] mas = new int[100, 100];
- int n = 0, m = 0;
- private void button1_Click(object sender, EventArgs e)
- {
- textBox3.Text = "";
- m = Convert.ToInt32(textBox1.Text); n = Convert.ToInt32(textBox2.Text);
- Random a = new Random();
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- mas[i, j] = a.Next(10);
- textBox3.Text = textBox3.Text + Convert.ToString(mas[i, j]) + " *";
- }
- textBox3.Text = textBox3.Text + System.Environment.NewLine;
- }
- int tmp = 0;
- for (int i = 0; i < m; i++)
- {
- tmp = mas[i, i];
- for (int j = n; j >= i; j--)
- mas[i, j] /= tmp;
- for (int j = i + 1; j < n; j++)
- {
- tmp = mas[j, i];
- for (int k = n; k >= i; k--)
- mas[j, k] -= tmp * mas[i, k];
- }
- }
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- textBox4.Text = textBox4.Text + mas[i, j].ToString() + " ";
- }
- textBox4.Text = textBox4.Text + System.Environment.NewLine;
- }
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д