martes, 13 de septiembre de 2011

Este programa maneja matrices

public partial class Form1 : Form{


{
InitializeComponent();
}


{
dgv1.RowCount = dgv2.RowCount = dgv3.RowCount =
}

{
dgv1.ColumnCount = dgv2.ColumnCount = dgv3.ColumnCount =
}

{
dgv1.Focus();
dgv2.Focus();
}

{





{
dgv1[j, i].Value = r.Next(0, 11);
dgv2[j, i].Value = r.Next(0, 11);
}
}

{

{11,12,13,14,15,16,17,18,19,20},
{21,22,23,24,25,26,27,28,29,30},
{31,32,33,34,35,36,37,38,39,40},
{41,42,43,44,45,46,47,48,49,50},
{51,52,53,54,55,56,57,58,59,60},
{61,62,63,64,65,66,67,68,69,70},
{71,72,73,74,75,76,77,78,79,80},
{81,82,83,84,85,86,87,88,89,90},
{91,92,93,94,95,96,97,98,99,100}};



{


dgv1.Rows[ren].Cells[col].Value =
}
Matriz mat = new Matriz();public Form1()private void numericUpDown1_ValueChanged(object sender, EventArgs e)int.Parse(numericUpDown1.Value.ToString());private void numericUpDown2_ValueChanged(object sender, EventArgs e)int.Parse(numericUpDown2.Value.ToString());private void radioButton1_CheckedChanged(object sender, EventArgs e)private void radioButton2_CheckedChanged(object sender, EventArgs e)int ren = Convert.ToInt32(numericUpDown1.Value);int col = Convert.ToInt32(numericUpDown2.Value);Random r= new Random();for(int i = 0; i < ren; i++)for (int j = 0; j < col; j++)private void radioButton3_CheckedChanged(object sender, EventArgs e)int[,] aux ={{1,2,3,4,5,6,7,8,9,10},int nr = Convert.ToInt32(numericUpDown1.Value);int nc = int.Parse(numericUpDown2.Value.ToString());if ((nr >= 3 && nr <= 10) && (nc >= 3 && nc <= 10))for (int ren = 0; ren < dgv1.RowCount; ren++)for (int col = 0; col < dgv1.ColumnCount; col++)int.Parse(aux[ren, col].ToString());else{MessageBox.Show("solo se aceptan valores entre 1 y 10 \n introduce otra vez los valores: ");//numericUpDown1.Value=radioButton1.Checked =
radioButton2.Checked =
radioButton3.Checked =

}
}

{



{

mat.Multiplicacion(dgv1, dgv2, dgv3);
}
false;false;false;return;private void button1_Click(object sender, EventArgs e)int ren = Convert.ToInt32(numericUpDown1.Value);int col = Convert.ToInt32(numericUpDown2.Value);if (ren == col)else
}


{


mat.Suma(dgv1, dgv2, dgv3);
}

{


mat.Resta(dgv1, dgv2, dgv3);
}

{




{


{
suma +=
j++;
}
textBox5.Text = suma.ToString();
}
MessageBox.Show("Error! Matriz no Apta para la Funcion de Multiplicacion.");private void button4_Click(object sender, EventArgs e)int ren = Convert.ToInt32(numericUpDown1.Value);int col = Convert.ToInt32(numericUpDown2.Value);private void button5_Click(object sender, EventArgs e)int ren = Convert.ToInt32(numericUpDown1.Value);int col = Convert.ToInt32(numericUpDown2.Value);private void radioButton8_CheckedChanged(object sender, EventArgs e)int ren = Convert.ToInt32(numericUpDown1.Value);int col = Convert.ToInt32(numericUpDown2.Value);int suma = 0;if (ren == col)int j = 0;for (int i = 0; i < col; i++)Convert.ToInt32(dgv1[j, i].Value);else
}

{



{



{
suma +=
j--;
}
textBox6.Text = suma.ToString();
}
MessageBox.Show("Error! Matriz no apta para la suma de la Diagonal Principal.");private void radioButton9_CheckedChanged(object sender, EventArgs e)int ren = Convert.ToInt32(numericUpDown1.Value);int col = Convert.ToInt32(numericUpDown2.Value);if (ren == col)int j = col - 1;int suma = 0;for (int i = 0; i < ren; i++)Convert.ToInt32(dgv1[j, i].Value);else
}

{
textBox7.Text =
}

{
textBox8.Text =
}

{
}

class Matriz{



{
}

{
ren = r;
col = c;
mat =
}

{

{

{
dgv3[j, i].Value =
}
}
}

{

{

{
dgv3[j, i].Value =
}
}
}

{


{
dgv3[j, i].Value = 0;

dgv3[j, i].Value =
}
}

{



mayor =

}

{



menor =

}
}
private int[,] mat;int ren, col;public Matriz()public Matriz(int r, int c)new int[ren, col];public void Suma(DataGridView dgv1, DataGridView dgv2, DataGridView dgv3)for (int i = 0; i < ren; i++)for (int j = 0; j < col; j++)Convert.ToInt32(dgv1[j, i].Value) + Convert.ToInt32(dgv2[j, i].Value);public void Resta(DataGridView dgv1, DataGridView dgv2, DataGridView dgv3)for(int i = 0; i < ren; i++)for(int j = 0; j < col; j++)Convert.ToInt32(dgv1[j, i].Value) + Convert.ToInt32(dgv2[j, i].Value); public void Multiplicacion(DataGridView dgv1, DataGridView dgv2, DataGridView dgv3)for (int i = 0; i < ren; i++)for (int j = 0; j < ren; j++)for (int k = 0; k < ren; k++)Convert.ToInt32(dgv3[j, i].Value) + Convert.ToInt32(dgv1[k, i].Value) * Convert.ToInt32(dgv2[j, k].Value);public int Mayor(DataGridView dgv)int mayor = Convert.ToInt32(dgv[0, 0].Value);for (int i = 1; i < dgv.RowCount; i++)if (mayor < Convert.ToInt32(dgv[0, i].Value))Convert.ToInt32(dgv[0, i].Value);return mayor;public int Menor(DataGridView dgv)int menor = Convert.ToInt32(dgv[0, 0].Value);for (int i = 1; i < dgv.RowCount; i++)if (menor > Convert.ToInt32(dgv[0, i].Value))Convert.ToInt32(dgv[0, i].Value);return menor;
MessageBox.Show("Error! Matriz no apta para la suma de la Diagonal Invertida.");private void radioButton5_CheckedChanged(object sender, EventArgs e)Convert.ToString(mat.Menor(dgv1));private void radioButton4_CheckedChanged(object sender, EventArgs e)Convert.ToString(mat.Mayor(dgv1));private void Form1_Load(object sender, EventArgs e)

No hay comentarios:

Publicar un comentario