using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
public void InputMatrix(ref int[,]a)
{
for (int i = 0; i < 3; i++) //row
{
for (int j = 0; j < 3; j++) //column
{
Console.Write("Enter the Number at index X[{0},{1}] = ", i, j);
a[i, j] = int.Parse(Console.ReadLine());
Console.WriteLine();
}
}
}
public void printMatrix(int [,]a)
{
for (int i = 0; i < 3; i++) //row
{
for (int j = 0; j < 3; j++) //column
{
Console.Write(a[i, j] + "\t");
}
Console.WriteLine();
}
}
public int[,] sum(int[,] a, int[,]b)
{
int[,] c = new int[3, 3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
c[i, j] = a[i, j] + b[i, j];
}
}
return c;
}
static void Main(string[] args)
{
Program p = new Program();
int[,] x = new int[3, 3];
int[,] y = new int[3, 3];
int[,] z = new int[3, 3];
p.InputMatrix(ref x);
Console.WriteLine("\n---------------------Matrix A---------------\n");
p.printMatrix(x);
p.InputMatrix(ref y);
Console.WriteLine("\n---------------------Matrix B---------------\n");
p.printMatrix(y);
z = p.sum(x,y);
Console.WriteLine("\n---------------------Matrix C ---------------\n");
p.printMatrix(z);
Console.ReadLine();
}
}
}
No comments:
Post a Comment