0% found this document useful (0 votes)
36 views6 pages

Matrices: Lic. Viviana Pardo

The document describes a C# program to add two matrices. It defines functions to read in two matrices of user-specified size from the console, display the individual matrices, and calculate their sum by iterating through and adding the elements of the corresponding positions and storing the results in a third matrix. The main function calls the other functions to read in the matrices, display the originals and summed result, and handle user input and output.

Uploaded by

jhoselin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views6 pages

Matrices: Lic. Viviana Pardo

The document describes a C# program to add two matrices. It defines functions to read in two matrices of user-specified size from the console, display the individual matrices, and calculate their sum by iterating through and adding the elements of the corresponding positions and storing the results in a third matrix. The main function calls the other functions to read in the matrices, display the originals and summed result, and handle user input and output.

Uploaded by

jhoselin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lic.

Viviana Pardo

MATRICES
Lic. Viviana Pardo
Lic. Viviana Pardo

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

namespace CASuma2Matrices
{
class Program
{
static void Main(string[] args)
{
int nf, nc;
int[,] Matriz = new int[100,100];

Console.Write("Numero Filas: ");


nf = int.Parse(Console.ReadLine());
Console.Write("Numero de Columnas: ");
nc= Convert.ToInt32(Console.ReadLine());
leerMatriz(Matriz, nf, nc);
Console.Clear();
Console.WriteLine("La matriz es: ");
mostrarMatriz(Matriz, nf, nc);
Console.ReadLine();
}
static void leerMatriz(int[,] A, int n, int m)
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{

Console.Write("Escribe el nombre para elemento {0} {1}: ", i, j);


A[i,j] = Convert.ToInt32(Console.ReadLine());

}
}
}
static void mostrarMatriz(int[,] A, int n, int m)
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
Console.Write("{0} ", A[i, j]);
}
Console.WriteLine(" ");
}
}
}
}
Lic. Viviana Pardo

SUMAR DOS MATRICES


Lic. Viviana Pardo

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

namespace CASuma2Matrices
{
class Program
{
static void Main(string[] args)
{
int nf, nc;
int[,] R, Matriz2;
int[,] Matriz1 = new int[100,100];
// int[,] Matriz2;
Matriz2 = new int[100, 100];
R = new int[100, 100];

Console.Write("Numero Filas: ");


nf = int.Parse(Console.ReadLine());
Console.Write("Numero de Columnas: ");
nc= Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Introducir los elementos de la Matriz 1: ");
leerMatriz(Matriz1, nf, nc);
Console.WriteLine("Introducir los elementos de la Matriz 2: ");
leerMatriz(Matriz2, nf, nc);
sumaMatrices(Matriz1, Matriz2, R, nf, nc);
Console.Clear();
Console.WriteLine("La matriz 1 es: ");
mostrarMatriz(Matriz1, nf, nc);
Console.WriteLine("La matriz 2 es: ");
mostrarMatriz(Matriz2, nf, nc);
Console.WriteLine("La matriz resultante es: ");
mostrarMatriz(R, nf, nc);
Console.ReadLine();
}
static void leerMatriz(int[,] A, int n, int m)
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
Console.Write("Escribe el nombre para elemento {0} {1}: ", i, j);
A[i,j] = Convert.ToInt32(Console.ReadLine());

}
}
}
static void mostrarMatriz(int[,] A, int n, int m)
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
Console.Write("{0} ", A[i, j]);
Lic. Viviana Pardo

}
Console.WriteLine(" ");
}
}
static void sumaMatrices(int[,] A, int[,] B, int[,] C, int n, int m)
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
C[i, j] = A[i, j] + B[i, j];

}
}
}
}
}

You might also like