You are on page 1of 5

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 WFAP_Matrice
{
public partial class Form1 : Form
{
int i = 1, j = 1, n, m;
private int[,] mat = new int[100, 100];
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
n = Int32.Parse(textBox1.Text);
m = Int32.Parse(textBox2.Text);
MessageBox.Show("Bun, deci matricea va avea " + n +
" linii si " + m + " coloane");
textBox1.ReadOnly = true;
textBox2.ReadOnly = true;
}
catch (Exception)
{
}
}
private void button2_Click(object sender, EventArgs e)
{
if (i <= n && j<= m)
{
try
{
mat[i, j] = Int16.Parse(textBox3.Text);
}
catch (Exception)
{
}
if (j < m)
j++;
else
{
i++;
j = 1;
}
label3.Text = "mat[" + i + "," + j + "]=";
if (i == n + 1)
{
button2.Enabled = false;
textBox3.ReadOnly = true;
label3.Text = "Done";
}
textBox3.Text = "";
textBox3.Focus();

}
}
private void button3_Click(object sender, EventArgs e)
{
i = 1; j = 1;
for (i = 1; i <= n; i++)
{
textBox4.Text = textBox4.Text + Environment.NewLine;
for (j = 1; j <= m; j++)
{
textBox4.Text = textBox4.Text + mat[i, j] +
" ";
}
}
}
private void button4_Click(object sender, EventArgs e)
{
textBox4.Text = "";
i = 1; j = 1; n = 1; m = 1;
label3.Text = "mat[1,1]";
textBox1.ReadOnly = false;
textBox2.ReadOnly = false;
textBox3.ReadOnly = false;
button2.Enabled = true;
textBox1.Text = "";
textBox2.Text = "";
textBox7.Text = "";
textBox5.Text = "";
textBox6.Text = "";
}
private void Form1_Load(object sender, EventArgs e)
{
radioButton1.Checked = true;
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
label4.Text = "Inverseaz linia:";
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
label4.Text = "Inverseaz coloana:";
}
}
private void button5_Click(object sender, EventArgs e)
{
int l1 = 1, l2 = 1;
try
{
l1 = Int32.Parse(textBox5.Text);
l2 = Int32.Parse(textBox6.Text);
}
catch (Exception)
{

}
if (radioButton1.Checked == true)
{
i = 1; j = 1;
int[,] mat2 = new int[100, 100];
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
mat2[i, j] = mat[i, j];
}
}
textBox7.Text = textBox7.Text + Environment.NewLine;
textBox7.Text = textBox7.Text + "Elementele de pe li
nia " + l1 + " sunt:";
for (j = 1; j <= m; j++)
{
textBox7.Text = textBox7.Text + mat[l1, j] +
" ";
}
textBox7.Text = textBox7.Text + Environment.NewLine;
textBox7.Text = textBox7.Text + "Elementele de pe li
nia " + l2 + " sunt:";
for (j = 1; j <= m; j++)
{
textBox7.Text = textBox7.Text + mat[l2, j] +
" ";
}
textBox7.Text = textBox7.Text + Environment.NewLine;
textBox7.Text = textBox7.Text + "Matricea cu cele do
u linii inversate este:";
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
mat2[l2, j] = mat[l1, j];
mat2[l1, j] = mat[l2, j];
}
}
for (i = 1; i <= n; i++)
{
textBox7.Text = textBox7.Text + Environment.
NewLine;
for (j = 1; j <= m; j++)
{
textBox7.Text = textBox7.Text + mat2
[i, j] + " ";
}
}
}
if (radioButton2.Checked == true)
{
i = 1; j = 1;
int[] vec = new int[100];
int[,] mat2 = new int[100, 100];
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
mat2[i, j] = mat[i, j];

}
}
textBox7.Text = textBox7.Text + Environment.NewLine;
textBox7.Text = textBox7.Text + "Elementele de pe co
loana " + l1 + " sunt:";
for (i = 1; i <= n; i++)
{
textBox7.Text = textBox7.Text + mat[i, l1] +
" ";
}
textBox7.Text = textBox7.Text + Environment.NewLine;
textBox7.Text = textBox7.Text + "Elementele de pe co
loana " + l2 + " sunt:";
for (i = 1; i <= n; i++)
{
textBox7.Text = textBox7.Text + mat[i, l2] +
" ";
}
textBox7.Text = textBox7.Text + Environment.NewLine;
textBox7.Text = textBox7.Text + "Matricea cu cele do
u coloane inversate este:";
for (i = 1; i <= n; i++)
{
mat2[i, l2] = mat[i, l1];
mat2[i, l1] = mat[i, l2];
}
for (i = 1; i <= n; i++)
{
textBox7.Text = textBox7.Text + Environment.
NewLine;
for (j = 1; j <= m; j++)
{
textBox7.Text = textBox7.Text + mat2
[i, j] + " ";
}
}
}
}
private void button6_Click(object sender, EventArgs e)
{
int min = 9;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
if (mat[i, j] < min)
min = mat[i, j];
}
}
textBox7.Text = textBox7.Text + Environment.NewLine + "Eleme
ntul minim din matrice este " + min;
}
private void button7_Click(object sender, EventArgs e)
{
int max = 0;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
if (mat[i, j] > max)

max = mat[i, j];


}
}
textBox7.Text = textBox7.Text + Environment.NewLine + "Eleme
ntul maxim din matrice este " + max;
}
private void button8_Click(object sender, EventArgs e)
{
textBox7.Text = textBox7.Text + Environment.NewLine + "Eleme
ntele de pe diagonala principala sunt: ";
int sumadp=0;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
textBox7.Text = textBox7.Text + mat[i, j] +
" ";
sumadp = sumadp + mat[i, j];
i = i + 1;
}
}
textBox7.Text = textBox7.Text + Environment.NewLine + "Suma
elementelor de pe diagonala principala este " + sumadp;
}
private void button9_Click(object sender, EventArgs e)
{
textBox7.Text = textBox7.Text + Environment.NewLine
+ "Elementele de pe diagonala secundar sunt: ";
int sumads = 0;
i = 1; j = n;
while (i != n + 1)
{
if (j <= m)
{
textBox7.Text = textBox7.Text + mat[
i, j] + " ";
j = j - 1;
i = i + 1;
sumads = sumads + mat[i, j];
}
}
textBox7.Text = textBox7.Text + Environment.NewLine
+ "Suma elementelor de pe diagonala secundar este " + sumads;
}
}
}

You might also like