Está en la página 1de 6

Universidad “Peruana los Andes” -Filial Lima E.A.P.

Ingeniería de Sistemas y Computación

FACULTAD DE INGENIERIA
E.A.P. INGENIERIA DE SISTEMAS Y
COMPUTACION
LABORATORIO Nº 01
U.E.C. Taller X Programación .NET II
TEMA Ejercicio de matrices en C#
Docentes 1. Mg. Santos Sotelo Antaurco Fecha 01/09/19 CICLO VI

I. OBJETIVOS
Al término de esta experiencia, el estudiante será capaz de:
 Identificar: El Entorno VISUAL STUDIO
 Analizar: Los procedimientos algorítmicos
 Aplicar: Las técnicas de aplicación en el desarrollo del proceso
 Evaluar: El resultado del proceso

II. EQUIPOS Y MATERIALES


 Computador
 Software Java con plataforma NetBeans
 Guía de Laboratorio
 Material impreso con la información de la sesión de aprendizaje.

III. METODOLOGIA Y ACTIVIDADES


 Elabore los diseños propuestos en clase de acuerdo a los temas desarrollados en
la Sesión de Aprendizaje.
 Presentar los avances de cada uno de los diseños al docente o jefe de práctica
encargado para la calificación correspondiente.
 Guardar sus diseños con un nombre apropiado dentro de la carpeta preparada
para este laboratorio.
 Apagar apropiadamente el computador y dejar ordenado su lugar de trabajo antes
de retirarse del laboratorio.

IV. IMPORTANTE
Antes de iniciar con el desarrollo del Laboratorio, crearemos siempre, una carpeta, donde
se guardará toda la información del presente laboratorio. Para ello realice lo siguiente:
 En el interfaz de VISUAL STUDIO, seleccione el Menu de Archivo, luego seleccionar
el comando Nuevo y posteriormente el Proyecto, ahora asignar un nombre, luego
haga click en Siguiente, que al final haga clic en crear, se genera el interfaz del
proyecto para codificar.

V. PROCEDIMIENTO

A continuación desarrolle cada uno de los siguientes ejercicios :

1 Mg. Santos Sotelo Antaurco


Universidad “Peruana los Andes” -Filial Lima E.A.P. Ingeniería de Sistemas y Computación

Ejercicios Resueltos de Matrices en C#

Ejemplo 1

Crear una matriz de 3 filas por 4 columnas con elementos de tipo int, ingresar sus posiciones y luego
imprimirlas.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Matriz
{
class Matriz
{
private int[,] mat;

public void Ingresar()


{
mat = new int[3, 4];
for (int f = 0; f < 3; f++)
{
for (int c = 0; c < 4; c++)
{
Console.Write("Ingrese posicion [" + (f + 1) + "," + (c + 1) + "]: ");
string linea;
linea = Console.ReadLine();
mat[f, c] = int.Parse(linea);
}
}
}

public void Imprimir()


{
for (int f = 0; f < 3; f++)
{
for (int c = 0; c < 4; c++)
{
Console.Write(mat[f, c] + " ");
}
Console.WriteLine();
}
Console.ReadKey();
}

static void Main(string[] args)


{
Matriz ma = new Matriz();
ma.Ingresar();
ma.Imprimir();
}
}
}

Ejemplo 2

Crear una matriz de 3 filas por 4 columnas e ingresar valores enteros, imprimir la primer fila. Imprimir la
última fila e imprimir la primer columna
using System;
using System.Collections.Generic;
using System.Linq;

2 Mg. Santos Sotelo Antaurco


Universidad “Peruana los Andes” -Filial Lima E.A.P. Ingeniería de Sistemas y Computación
using System.Text;

namespace Matriz
{
class Matriz
{
private int[,] mat;

public void Cargar()


{
mat = new int[3, 4];
for (int f = 0; f < 3; f++)
{
for (int c = 0; c < 4; c++)
{
Console.Write("Ingrese posicion [" + (f + 1) + "," + (c + 1) + "]: ");
string linea;
linea = Console.ReadLine();
mat[f, c] = int.Parse(linea);
}
}
}

public void PrimerFila()


{
Console.WriteLine("\nPrimer fila de la matriz:");
for (int c = 0; c < 4; c++)
{
Console.Write(mat[0, c] + " ");
}
}

public void UltimaFila()


{
Console.WriteLine("\nUltima fila de la matriz:");
for (int c = 0; c < 4; c++)
{
Console.Write(mat[2, c] + " ");
}
}

public void PrimerColumna()


{
Console.WriteLine("\nPrimer columna:");
for (int f = 0; f < 3; f++)
{
Console.Write(mat[f, 0] + " ");
}
}

static void Main(string[] args)


{
Matriz ma = new Matriz();
ma.Cargar();
ma.PrimerFila();
ma.UltimaFila();
ma.PrimerColumna();
Console.ReadKey();
}
}
}

3 Mg. Santos Sotelo Antaurco


Universidad “Peruana los Andes” -Filial Lima E.A.P. Ingeniería de Sistemas y Computación

Ejemplo 3

Realizar un programa que permita imprimir la siguiente serie:

1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
1 0 1 0 1 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PruebaVector
{
class PruebaVector
{
private int[,] serie;

public void Cargar()


{
serie = new int[10, 10];
for (int i = 1; i <= 6; i++)
{
for (int j = 1; j <= 6; j++)
{
if (j % 2 == 0)
{
serie[i, j] = 0;
}
else
{
serie[i, j] = 1;
}
}
}
}

public void visualizar()


{
for (int i = 1; i <= 5; i++)
4 Mg. Santos Sotelo Antaurco
Universidad “Peruana los Andes” -Filial Lima E.A.P. Ingeniería de Sistemas y Computación
{
Console.Write("\n");
for (int j = 1; j <= 6; j++)
{
Console.Write(serie[i, j] + " ");
}
}
Console.ReadKey();
}

static void Main(string[] args)


{
PruebaVector pv = new PruebaVector();
pv.Cargar();
pv.visualizar();
}
}
}

Ejemplo 4

Realizar un programa que permita la suma de dos matrices de 3x3 y


el resultado almacenar en un tercer matriz
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PruebaVector
{
class PruebaVector
{
private int[,] MatrizA;
private int[,] MatrizB;
private int[,] MatrizC;

public void Cargar()


{
MatrizA = new int[10, 10];
MatrizB = new int[10, 10];
MatrizC = new int[10, 10];

Console.WriteLine("Ingresando datos al matriz A");


for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= 3; j++)
{
Console.Write("Ingrese posicion [" + i + "," + j + "]: ");
string linea;
linea = Console.ReadLine();
MatrizA[i, j] = int.Parse(linea);
}
}

Console.WriteLine("Ingresando datos al matriz B");


for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= 3; j++)
{
Console.Write("Ingrese posicion [" + i + "," + j + "]: ");
string linea;
linea = Console.ReadLine();
MatrizB[i, j] = int.Parse(linea);
}
}

5 Mg. Santos Sotelo Antaurco


Universidad “Peruana los Andes” -Filial Lima E.A.P. Ingeniería de Sistemas y Computación

//Sumamos la matrizA y la MatrizB


for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= 3; j++)
{
MatrizC[i, j] = MatrizA[i, j] + MatrizB[i, j];
}
}
}
// visualizamos la suma de las matrices
public void visualizar()
{
Console.WriteLine("La suma de la MatrizA y MatrizB es :");
for (int i = 1; i <= 3; i++)
{
Console.Write("\n");
for (int j = 1; j <= 3; j++)
{
Console.Write(MatrizC[i, j] + " ");
}
}
Console.ReadKey();
}

static void Main(string[] args)


{
PruebaVector pv = new PruebaVector();
pv.Cargar();
pv.visualizar();
}
}
}

6 Mg. Santos Sotelo Antaurco

También podría gustarte