Sunteți pe pagina 1din 19

-1.

MOSTRAR UNA MATRIZ CUALQUIERA


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication149 { class Program { static void Main(string[] args) { int[,] mat1; int filas, columnas, x, y; Console.WriteLine("cuantas filas?"); filas = int.Parse(Console.ReadLine()); Console.WriteLine("cuantas columnas?"); columnas = int.Parse(Console.ReadLine()); { mat1 = new int[filas, columnas]; Console.WriteLine("ingrese valores de la matriz"); Console.WriteLine(""); for (x = 0; x < filas; x++) { for (y = 0; y < columnas; y++) { Console.WriteLine("ingrese valores para la posicion {0} , {1}", x, y); mat1[x, y] = int.Parse(Console.ReadLine()); } } Console.WriteLine("la matriz es;"); Console.WriteLine("==============="); Console.WriteLine(""); for (x = 0; x < filas; x++) { for (y = 0; y < columnas; y++) { Console.Write("{0}\t", mat1[x, y]); } Console.WriteLine(""); } } } } }

2.MOSTRAR UNA MATRIZ CUALQUIERA CUADRADA


using System;

using System.Collections.Generic; using System.Text; namespace ConsoleApplication155 { class Program { static void Main(string[] args) { int[,] mat1; int n,x,y;

Console.WriteLine("Ingrese orden de la matriz cuadrada"); n = int.Parse(Console.ReadLine()); {

mat1 = new int[n, n]; Console.WriteLine("ingrese valores de la matriz"); Console.WriteLine(""); for (x = 0; x < n; x++) { for (y = 0; y < n; y++) { Console.WriteLine("ingrese valores para la posicion {0} , {1}", x, y); mat1[x, y] = int.Parse(Console.ReadLine()); } } Console.WriteLine("la matriz es;"); Console.WriteLine("==============="); Console.WriteLine(""); for (x = 0; x < n; x++) { for (y = 0; y < n; y++) { Console.Write("{0}\t", mat1[x, y]); } Console.WriteLine(""); } } } } }

3.PROGRAMA QUE HALLA LA SUMA DE DOS MATRICES DE MxN.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication107

{ class Program { static void Main(string[] args) { //declaramos los arrays int[,] mat1; int[,] mat2; int[,] suma; //declaramos las variables int filas, columnas, i, j; //ingresamos la cantidad de filas y columnas de la matriz Console.WriteLine("Cuntas filas tendr la la matriz"); filas=int.Parse(Console.ReadLine()); Console.WriteLine("Cuntas columnas tendr la matriz"); columnas=int.Parse(Console.ReadLine()); //definimos el tamao del array mat1 = new int[filas, columnas]; mat2 = new int[filas, columnas]; suma=new int[filas,columnas]; //ingresamos los valores de la primera matriz Console.WriteLine("Ingrese valores de la matriz N 1"); Console.WriteLine(""); for (i = 0; i < filas; i++) { for (j = 0; j < columnas; j++) { Console.WriteLine("Ingrese valor para la posicin {0},{1}",i,j); mat1[i,j]=int.Parse(Console.ReadLine()); } } //Ingresamos los valores de la segunda matriz Console.WriteLine("Ingrese valores para la matriz N2"); Console.WriteLine(""); for (i = 0; i < filas; i++) { for (j = 0; j < columnas; j++) { Console.WriteLine("Ingrese valor para la posicin {0},{1}", i, j); mat2[i, j] = int.Parse(Console.ReadLine()); } } //suma de las matrices for (i = 0; i < filas; i++) { for (j = 0; j < columnas; j++) { suma[i, j] = mat1[i, j] + mat2[i, j]; } }

//impresion en pantalla de la suma Console.WriteLine("La suma de las matrices es: "); Console.WriteLine(" "); for (i = 0; i < filas; i++) { for (j = 0; j < columnas; j++) { Console.Write("{0}\t",suma[i,j]); } Console.WriteLine(""); } } } }

4.PROGRAMA QUE HALLA LA SUMA DE FILAS.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication91 { class Program { static void Main(string[] args) { int nfilas, ncol; do { Console.WriteLine("Numero de filas de la matriz: "); nfilas=int.Parse(Console.ReadLine()); } while(nfilas<1); do { Console.WriteLine("Numero de columnas de la matriz: "); ncol=int.Parse(Console.ReadLine()); } while(ncol<1); float[,] m; m=new float[nfilas,ncol]; int i = 0, j = 0; float sumafila = 0; Console.WriteLine("Introducir los valores de la matriz"); for (i = 0; i < nfilas; i++) { for (j = 0; j < ncol; j++) { Console.Write("Ingrese valor de la posicion{0}, ",i,j);

{1}:

m[i,j]=int.Parse(Console.ReadLine()); } } Console.WriteLine(); for (i = 0; i < nfilas; i++) { sumafila = 0; for (j = 0; j < ncol; j++) sumafila=sumafila+m[i, j]; Console.WriteLine("Suma de la fila{0}",sumafila); } } } }

3.TRANSPUESTA
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication78 { class Program { static void Main(string[] args) { int[,] mat1; int filas, columnas, x, y; Console.WriteLine("cuantas filas?"); filas = int.Parse(Console.ReadLine()); Console.WriteLine("cuantas columnas?"); columnas = int.Parse(Console.ReadLine()); { mat1 = new int[filas, columnas]; Console.WriteLine("ingrese valores de la matriz"); Console.WriteLine(""); for (x = 0; x < filas; x++) { for (y = 0; y < columnas; y++) { Console.WriteLine("ingrese valores para la posicion {0} , {1}", x, y); mat1[x, y] = int.Parse(Console.ReadLine()); } } Console.WriteLine("la matriz es;"); Console.WriteLine("==============="); Console.WriteLine("");

for (x = 0; x < filas; x++) { for (y = 0; y < columnas; y++) { Console.Write("{0}\t", mat1[x, y]); } Console.WriteLine(""); } { Console.WriteLine("la matriz traspuesta es:"); Console.WriteLine("======================="); Console.WriteLine(""); for (y = 0; y < columnas; y++) { for (x = 0; x < filas; x++) { Console.Write("{0} \t", mat1[x, y]); } { Console.WriteLine(""); } } } } } } }

4.TABLA DE TEMPERTURAS Y DIAS


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication123 { class Program { static void Main(string[] args) { int[,] tem; tem = new int[3, 7] { {1,2,3,4,5,6,7}, {9,7,654,43,3,3,5}, {3,6,7,8,9,96,3,} }; for (int dia = 0; dia < 7; dia++) { for (int i = 0; i < 3; i++) Console.WriteLine("Valores dia {0}: {1}",dia,tem[i,dia]); Console.WriteLine(); } }

} }

5.MATRIZ IDENTIDAD
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication138 { class Program { static void Main(string[] args) { int n; Console.WriteLine("Ingrese el orden de la matriz:"); n = int.Parse(Console.ReadLine()); int[,] matriz = new int[n, n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { matriz[i, j] = 1; } else { matriz[i, j] = 0; } } }

for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Console.Write("{0} ", matriz[i, j]); } Console.WriteLine(); } Console.ReadLine(); } }

6.DECIR SI UN ALUMNO APROBO O NO EN DIVERSOS CURSOS Y PROMEDIOS USANDO MATRICES.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication144 { class Program { static void Main(string[] args) { int i = 0, j = 0, filas = 7; double d; System.Console.WriteLine("\nEscribe el numero de alumnos"); int numa = Convert.ToInt16(Console.ReadLine()); double[,] table = new double[numa, filas]; for (i = 0; i < numa; i++) { Console.WriteLine("ingresa la calificacion de el alumno en espaol {0}", i + 1); table[i, 0] = Int32.Parse(Console.ReadLine()); } for (i = 0; i < numa; i++) { System.Console.WriteLine("Escribe la calificacion alumno matematicas {0}", i + 1); table[i, 1] = Int32.Parse(Console.ReadLine()); } for (i = 0; i < numa; i++) { System.Console.WriteLine("Escribe la calificacion alumno fisica {0}", i + 1); table[i, 2] = Int32.Parse(Console.ReadLine()); } for (i = 0; i < numa; i++) { System.Console.WriteLine("Escribe la calificacion alumno quimica {0}", i + 1); table[i, 3] = Int32.Parse(Console.ReadLine()); } for (i = 0; i < numa; i++) { System.Console.WriteLine("Escribe la calificacion alumno geografia {0}", i + 1); table[i, 4] = Int32.Parse(Console.ReadLine()); } for (i = 0; i < numa; i++) { System.Console.WriteLine("Escribe la calificacion alumno historia {0}", i + 1); table[i, 5] = Int32.Parse(Console.ReadLine()); } Console.Clear();

de

de

de

de

de

System.Console.WriteLine("\nLas calificaciones de alumno son:\n\n"); for (j = 0; j < numa; j++) { d = (table[j, 0] + table[j, 1] + table[j, 2] + table[j, 3] + table[j, 4] + table[j, 5]) / 6;//Exception??? table[j, 6] = d; System.Console.WriteLine("Del alumano {0}\n", j + 1); System.Console.WriteLine("Espaol : {0}", table[j, 0]); System.Console.WriteLine("Matematicas : {0}", table[j, 1]); System.Console.WriteLine("Fisica : {0}", table[j, 2]); System.Console.WriteLine("Quimica : {0}", table[j, 3]); System.Console.WriteLine("Geografia : {0}", table[j, 4]); System.Console.WriteLine("Historia : {0}", table[j, 5]); if (table[j, 6] <= 6) { System.Console.WriteLine("\nEl alumno reprobo con un promedio de: {0}", table[j, 6]); } else if (table[j, 6] >= 7) { System.Console.WriteLine("\nEl alumno aprobo con un promedio de: {0}", table[j, 6]); } } }

} }

7.MENU QUE TIENE 3 OPERACIONES SUMA RESTA Y MULT DE MATRICES BIDIMENSIONALES.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication145 { class Program { public static void Main(string[] args) { float[,] mat1; // Las matrices float[,] mat2; int f1, c1; matrices int f2, c2; //Llamamos al menu y recojemos la opcin seleccionada // El nmero de filas y columnas de las

byte opcion; do { opcion = menu(); } while (opcion >= 5); switch (opcion) { case 1: // SUMA // Leemos el nmero de filas y columnas de las matrices 1 y 2 Console.WriteLine("Introduzca el nmero de filas de las matrices 1 y 2"); f1 = int.Parse(Console.ReadLine()); Console.WriteLine("Introduzca el nmero de columnas de las matrices 1 y 2"); c1 = int.Parse(Console.ReadLine()); // Pedimos los datos de filas y columnas Console.WriteLine("Introduzca los datos de la matriz 1 enumerandolos por filas:"); mat1 = leer(f1, c1); Console.WriteLine("Introduzca los datos de la matriz 2 enumerandolos por filas:"); mat2 = leer(f1, c1); //Mostramos la suma de ambas matrices suma(mat1, mat2); break; case 2: // RESTA matrices 1 y 2 // Leemos el nmero de filas y columnas de las

Console.WriteLine("Introduzca el nmero de filas de las matrices 1 y 2"); f1 = int.Parse(Console.ReadLine()); Console.WriteLine("Introduzca el nmero de columnas de las matrices 1 y 2"); c1 = int.Parse(Console.ReadLine()); // Pedimos los datos de filas y columnas Console.WriteLine("Introduzca los datos de la matriz 1 enumerandolos por filas:"); mat1 = leer(f1, c1); Console.WriteLine("Introduzca los datos de la matriz 2 enumerandolos por filas:"); mat2 = leer(f1, c1); // Mostramos la resta de ambas matrices resta(mat1, mat2); break; case 3: // PRODUCTO POR UN ESCALAR matriz 1 de la matriz 1"); // Leemos el nmero de filas y columnas de la Console.WriteLine("Introduzca el nmero de filas

f1 = int.Parse(Console.ReadLine()); Console.WriteLine("Introduzca el nmero de columnas de la matriz 1"); c1 = int.Parse(Console.ReadLine()); float escalar; Console.WriteLine("Introduzca el escalar por el que quiere multiplicar la matriz"); escalar = float.Parse(Console.ReadLine()); // Pedimos los datos de filas y columnas Console.WriteLine("Introduzca los datos de la matriz 1 enumerandolos por filas:"); mat1 = leer(f1, c1); // Mostramos la solucin prodEscalar(mat1, escalar); break; } Console.ReadKey(); } // Funcin que muestra el menu de seleccin de operaciones public static byte menu() { try { byte opcion; Console.SetCursorPosition(10, 1); Console.WriteLine("Men:"); Console.SetCursorPosition(0, 3); Console.WriteLine("Elija la operacin que quiere hacer:"); Console.WriteLine("1 - Suma de matrices"); Console.WriteLine("2 - Resta de matrices"); Console.WriteLine("3 - Producto por un escalar"); opcion = byte.Parse(Console.ReadLine()); if (opcion >= 1 && opcion <= 3) { Console.Clear(); return opcion; } else { Console.Clear(); return 5; }

} catch { //En caso de error Console.Clear(); return 5; }

// Funcin que lee los datos de las matrices public static float[,] leer(int filas, int columnas) {

float[,] ret = new float[filas, columnas]; for (int fila = 0; fila < filas; fila++) { for (int columna = 0; columna < columnas; columna++) { ret[fila, columna] = float.Parse(Console.ReadLine()); } } return ret; } // La funcin suma public static void suma(float[,] mat1, float[,] mat2) { Console.WriteLine("La suma de sus dos matrices es (enumeradas por filas)"); for (int fila = 0; fila <= mat2.GetUpperBound(0); fila++) { for (int columna = 0; columna <= mat2.GetUpperBound(1); columna++) { float suma; suma = mat1[fila, columna] + mat2[fila, columna]; Console.WriteLine(suma.ToString()); } Console.WriteLine(""); } } // La funcin resta public static void resta(float[,] mat1, float[,] mat2) { Console.WriteLine("La resta de sus dos matrices es (enumeradas por filas)"); for (int fila = 0; fila <= mat2.GetUpperBound(0); fila++) { for (int columna = 0; columna <= mat2.GetUpperBound(1); columna++) { float resta; resta = mat1[fila, columna] - mat2[fila, columna]; Console.WriteLine(resta.ToString()); } Console.WriteLine(""); } } // Producto por un escalar public static void prodEscalar(float[,] mat1, float escalar) { Console.WriteLine("La multiplicacin del escalar por su matriz es (enumerada por filas)"); for (int fila = 0; fila <= mat1.GetUpperBound(0); fila++) { for (int columna = 0; columna <= mat1.GetUpperBound(1); columna++) { float esc; esc = mat1[fila, columna] * escalar; Console.WriteLine(esc.ToString());

} } } }

} Console.WriteLine("");

8. DETERMINANTE DE UNA MATRIZ DE 2*2.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication149 { class Program { static void Main(string[] args) { int[,] mat1; int x, y;

{ mat1 = new int[2, 2]; Console.WriteLine("ingrese valores de la matriz 2*2"); Console.WriteLine(""); for (x = 0; x < 2; x++) { for (y = 0; y < 2; y++) { Console.WriteLine("ingrese valores para la posicion {0} , {1}", x, y); mat1[x, y] = int.Parse(Console.ReadLine()); } } Console.WriteLine("la matriz es;"); Console.WriteLine("==============="); Console.WriteLine(""); for (x = 0; x < 2; x++) { for (y = 0; y < 2; y++) { Console.Write("{0}\t", mat1[x, y]); } Console.WriteLine(""); } for (x = 0; x < 2; x++) { for (y = 0; y < 2; y++) {

mat1[x, y] = (mat1[0, 0]) * (mat1[1, 1]) (mat1[1, 0]) *( mat1[0, 1]); } } Console.WriteLine("Su determinante es:"); Console.WriteLine("=================="); Console.WriteLine(""); Console.Write("{0}\t", mat1[0, 0]);

} } }

9.SUMA DE FILAS MENOS SUMA DE COLUMNAS


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication154 { class Program { static void Main(string[] args) { //declaramos el arrays int[,] mat1; //delclaramos las variables int filas, columnas, x, y, sumfilas = 0, sumcolumnas = 0, total, a = 0, b = 0; //ingresamos cantidad de filas y columnas de la matriz Console.Write("CUANTAS FILAS TENDRA LA MATRIZ:"); filas = int.Parse(Console.ReadLine()); Console.Write("CUANTAS COLUMNAS TENDRA LA MATRIZ:"); columnas = int.Parse(Console.ReadLine()); //definimos el tamao del array mat1 = new int[filas, columnas]; //ingresamos valores a la primera matriz Console.WriteLine("INGRESE LOS VALORES PARA LA PRIMERA MATRIZ:"); Console.WriteLine(""); for (x = 0; x < filas; x++) { for (y = 0; y < columnas; y++) { Console.WriteLine("ingrese valor para la posicion {0},{1}", x, y); mat1[x, y] = int.Parse(Console.ReadLine()); } } //SUMA DE FILAS MENOS SUMA DE COLUMNAS

if (a < filas) { for (y = 0; y < columnas; y++) { a = 0; sumfilas = mat1[a, y]; sumfilas = sumfilas + mat1[a, y]; } a = a + 1; } if (b < columnas) { for (x = 0; x < filas; x++) { b = 0; sumcolumnas = mat1[x, b]; sumcolumnas = sumcolumnas + mat1[x, b]; } b = b + 1; } //restando las sumas total = sumfilas - sumcolumnas; //impresion Console.WriteLine("LA OPERACION ES IGUAL A:"); Console.WriteLine("======================="); Console.WriteLine(""); Console.WriteLine("{0}\t", total); } } }

10.INVERSA DE UNA MATRIZ


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication155 { class Program { static void Main(string[] args) { //declaramos los array double[,] A;

double[,] invA; int[,] I; //declaramos las variables int grado, x, y; //ingresamos el grado de la matris cuadrada Console.Write("\nINGRESE EL GRADO DE LA MATRIZ CUADRADA :"); grado = int.Parse(Console.ReadLine()); // definimos el tamao del array A = new double[grado, grado]; invA = new double[grado, grado]; I = new int[grado, grado]; // ingreso los valores de la matriz A * \n"); Console.WriteLine("\n * Ingrese los elementos de la Matriz for (x = 0; x < grado; x++) { for (y = 0; y < grado; y++) { Console.Write("\tIngrese el elemento [{0},{1}] : } A[x, y] = double.Parse(Console.ReadLine());

", x, y);

} Console.Write("\n"); //definimos la matriz indentidad I for (x = 0; x < grado; x++) { for (y = 0; y < grado; y++) { if (x == y) { I[x, y] = 1; } else { I[x, y] = 0; } } }

// Calcular la matriz inversa Console.WriteLine("\n * La matriz inversa es *\n"); for (x = 0; x < grado; x++) { for (y = 0; y < grado; y++) { invA[x, y] = I[x, y] / A[x, y]; Console.Write("\t{0,10:f4}", invA[x, y]);

} } } }

} Console.Write("\n");

11.DIFERENCIA DE LA DIAGONAL PRINCIPAL Y SECUNDARIA DE UNA MATRIZ DE 3*3.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication155 { class Program { static void Main(string[] args) { int[,] ARREGLO1; int x, y, c, d, e; ARREGLO1 = new int[3, 3]; Console.WriteLine("ingrese valores de la diagonal principal "); for (x = 0; x < 3; x++) { for (y = 0; y < 3; y++) { { Console.WriteLine("ingrese el valor de {0}, {1}", x, y); ARREGLO1[x, y] = int.Parse(Console.ReadLine()); } } }

for (x = 0; x < 3; x++) { for (y = 0; y < 3; y++) { Console.Write("{0}\t", ARREGLO1[x, y]); } Console.WriteLine(""); } c = ARREGLO1[0, 0] + ARREGLO1[1, 1] + ARREGLO1[2, 2]; d = ARREGLO1[2, 0] + ARREGLO1[1, 1] + ARREGLO1[0, 2]; e = c - d; Console.WriteLine("la operacion es:{0}", e); }

12.HALLAR LA TRANSPUESTA Y VARIAS EL ORDEN DE LAS COLUMNAS DE 3*3.


using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication26 { class Program { static void Main(string[] args) { int[,] mat1; int[,] traspuesta; int x, y, columna, fila; Console.WriteLine("cuantas filas tendra la matris"); fila = int.Parse(Console.ReadLine()); Console.WriteLine("cuantas columnas tendra la matris"); columna = int.Parse(Console.ReadLine()); mat1 = new int[fila, columna]; traspuesta = new int[fila, columna]; Console.WriteLine("ingrede valores para la matris n1"); Console.WriteLine(""); for (x = 0; x < fila; x++) { for (y = 0; y < columna; y++) { Console.WriteLine("ingrese los datos en la posicion : {0}, {1}", x, y); mat1[x, y] = int.Parse(Console.ReadLine()); } } Console.WriteLine("las matris "); Console.WriteLine("======================== Console.WriteLine(""); for (x = 0; x < fila; x++) { for (y = 0; y < columna; y++) { Console.Write("{0}\t", mat1[x, y]); } Console.WriteLine(""); } for (x = 0; x < fila; x++) { for (y = 0; y < columna; y++) { traspuesta[x, 0] = mat1[1, x]; } } for (x = 0; x < fila; x++) { for (y = 0; y < columna; y++) { :");

traspuesta[x, 1] = mat1[0, x]; } for (x = 0; x < fila; x++) { for (y = 0; y < columna; y++) { traspuesta[x, 2] = mat1[2, x]; } } Console.WriteLine("las matris traspuesta es "); Console.WriteLine("======================== :"); Console.WriteLine(""); for (x = 0; x < fila; x++) { for (y = 0; y < columna; y++) { Console.Write("{0}\t", traspuesta[x, y]); } Console.WriteLine(""); } } } } }

S-ar putea să vă placă și