using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the Row size of Array");
int rowsize = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the column size of array");
int colsize = int.Parse(Console.ReadLine());
int[,] Matrix1=new int[rowsize,colsize];
for (int i = Matrix1.GetLowerBound(0); i <= Matrix1.GetUpperBound(0); i++)
{
for (int j = Matrix1.GetLowerBound(1); j <= Matrix1.GetUpperBound(0); j++)
{
Console.WriteLine("Enter Data of Matrix1 [{0} {1}]",i,j);
Matrix1[i, j] = int.Parse(Console.ReadLine());
}
}
int[,] Matrix2 = new int[rowsize, colsize];
for (int i = Matrix2.GetLowerBound(0); i <= Matrix2.GetUpperBound(0); i++)
{
for (int j = Matrix2.GetLowerBound(1); j <= Matrix2.GetUpperBound(0); j++)
{
Console.WriteLine("Enter Data of Matrix2 [{0} {1}]", i, j);
Matrix2[i, j] = int.Parse(Console.ReadLine());
}
}
Console.Clear();
Console.WriteLine("\n Displaying the Data of Matrix1 \n");
for (int i = Matrix1.GetLowerBound(0); i <= Matrix1.GetUpperBound(0); i++)
{
for (int j = Matrix1.GetLowerBound(1); j <= Matrix1.GetUpperBound(0); j++)
{
Console.Write(Matrix1[i, j] + "\t");
}
Console.WriteLine("\n");
}
Console.WriteLine("\n Displaying the Data of Matrix2 \n");
for (int i = Matrix2.GetLowerBound(0); i <= Matrix2.GetUpperBound(0); i++)
{
for (int j = Matrix2.GetLowerBound(1); j <= Matrix2.GetUpperBound(0); j++)
{
Console.Write(Matrix2[i,j]+"\t");
}
Console.WriteLine("\n");
}
int[,] Matrix3 = new int[rowsize, colsize];
Console.WriteLine("Press 1 for Addition");
Console.WriteLine("Press 2 for Substraction");
Console.WriteLine("Press 3 for Multiplication");
int userChoice = int.Parse(Console.ReadLine());
switch (userChoice)
{
case 1:
Console.WriteLine("\n Addition of Matrix1 and Matrix2 \n");
for (int i = Matrix3.GetLowerBound(0); i <= Matrix3.GetUpperBound(0); i++)
{
for (int j = Matrix3.GetLowerBound(1); j <= Matrix3.GetUpperBound(0); j++)
{
Matrix3[i, j] = Matrix1[i, j] + Matrix2[i, j];
Console.Write(Matrix3[i, j] + "\t");
}
Console.WriteLine("\n");
}
break;
case 2:
Console.WriteLine("\n Substraction of Matrix1 and Matrix2 \n");
for (int i = Matrix3.GetLowerBound(0); i <= Matrix3.GetUpperBound(0); i++)
{
for (int j = Matrix3.GetLowerBound(1); j <= Matrix3.GetUpperBound(0); j++)
{
Matrix3[i, j] = Matrix1[i, j] - Matrix2[i, j];
Console.Write(Matrix3[i, j] + "\t");
}
Console.WriteLine("\n");
}
break;
case 3:
Console.WriteLine("\n Multiplication of Matrix1 and Matrix2 \n");
for (int i = Matrix3.GetLowerBound(0); i <= Matrix3.GetUpperBound(0); i++)
{
for (int j = Matrix3.GetLowerBound(1); j <= Matrix3.GetUpperBound(0); j++)
{
Matrix3[i, j] = Matrix1[i, j] * Matrix2[i, j];
Console.Write(Matrix3[i, j] + "\t");
}
Console.WriteLine("\n");
}
break;
default:
Console.WriteLine("You entered invalid Option... Plz try again...");
break;
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the Row size of Array");
int rowsize = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the column size of array");
int colsize = int.Parse(Console.ReadLine());
int[,] Matrix1=new int[rowsize,colsize];
for (int i = Matrix1.GetLowerBound(0); i <= Matrix1.GetUpperBound(0); i++)
{
for (int j = Matrix1.GetLowerBound(1); j <= Matrix1.GetUpperBound(0); j++)
{
Console.WriteLine("Enter Data of Matrix1 [{0} {1}]",i,j);
Matrix1[i, j] = int.Parse(Console.ReadLine());
}
}
int[,] Matrix2 = new int[rowsize, colsize];
for (int i = Matrix2.GetLowerBound(0); i <= Matrix2.GetUpperBound(0); i++)
{
for (int j = Matrix2.GetLowerBound(1); j <= Matrix2.GetUpperBound(0); j++)
{
Console.WriteLine("Enter Data of Matrix2 [{0} {1}]", i, j);
Matrix2[i, j] = int.Parse(Console.ReadLine());
}
}
Console.Clear();
Console.WriteLine("\n Displaying the Data of Matrix1 \n");
for (int i = Matrix1.GetLowerBound(0); i <= Matrix1.GetUpperBound(0); i++)
{
for (int j = Matrix1.GetLowerBound(1); j <= Matrix1.GetUpperBound(0); j++)
{
Console.Write(Matrix1[i, j] + "\t");
}
Console.WriteLine("\n");
}
Console.WriteLine("\n Displaying the Data of Matrix2 \n");
for (int i = Matrix2.GetLowerBound(0); i <= Matrix2.GetUpperBound(0); i++)
{
for (int j = Matrix2.GetLowerBound(1); j <= Matrix2.GetUpperBound(0); j++)
{
Console.Write(Matrix2[i,j]+"\t");
}
Console.WriteLine("\n");
}
int[,] Matrix3 = new int[rowsize, colsize];
Console.WriteLine("Press 1 for Addition");
Console.WriteLine("Press 2 for Substraction");
Console.WriteLine("Press 3 for Multiplication");
int userChoice = int.Parse(Console.ReadLine());
switch (userChoice)
{
case 1:
Console.WriteLine("\n Addition of Matrix1 and Matrix2 \n");
for (int i = Matrix3.GetLowerBound(0); i <= Matrix3.GetUpperBound(0); i++)
{
for (int j = Matrix3.GetLowerBound(1); j <= Matrix3.GetUpperBound(0); j++)
{
Matrix3[i, j] = Matrix1[i, j] + Matrix2[i, j];
Console.Write(Matrix3[i, j] + "\t");
}
Console.WriteLine("\n");
}
break;
case 2:
Console.WriteLine("\n Substraction of Matrix1 and Matrix2 \n");
for (int i = Matrix3.GetLowerBound(0); i <= Matrix3.GetUpperBound(0); i++)
{
for (int j = Matrix3.GetLowerBound(1); j <= Matrix3.GetUpperBound(0); j++)
{
Matrix3[i, j] = Matrix1[i, j] - Matrix2[i, j];
Console.Write(Matrix3[i, j] + "\t");
}
Console.WriteLine("\n");
}
break;
case 3:
Console.WriteLine("\n Multiplication of Matrix1 and Matrix2 \n");
for (int i = Matrix3.GetLowerBound(0); i <= Matrix3.GetUpperBound(0); i++)
{
for (int j = Matrix3.GetLowerBound(1); j <= Matrix3.GetUpperBound(0); j++)
{
Matrix3[i, j] = Matrix1[i, j] * Matrix2[i, j];
Console.Write(Matrix3[i, j] + "\t");
}
Console.WriteLine("\n");
}
break;
default:
Console.WriteLine("You entered invalid Option... Plz try again...");
break;
}
}
}
No comments:
Post a Comment