C# code for adding two Matrices of any possible order.
On this topic
Optimize Your Computer by Cleaning It Up
How to Remember Not to Wear that Next Week
From the Dream of Democracy to the Reality of Dictatorship
Multitasking Technologies
using System;
namespace AdditionOfTwoMatrices
{
///
/// Summary description for Class1.
///
class Class1
{
public static int k=0,l=0,m=0,n=0;
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int [,]a=new int[10,10];
int [,]b=new int[10,10];
int [,]c=new int[10,10];
int [,]d=new int[10,10];
Class1 cs=new Class1();
Console.Write("Enter the order of First Matric : ");
k=int.Parse(Console.ReadLine());
Console.Write("- ");
m=int.Parse(Console.ReadLine());
Console.WriteLine();
Console.Write("Enter the order of Second Matric : ");
l=int.Parse( Console.ReadLine());
Console.Write("- ");
n=int.Parse(Console.ReadLine());
if(l==k && m==n)
{
Console.WriteLine("\nEnter The value of First Matrice:");
cs.matrice(a);
Console.WriteLine("Enter The value of Second Matrice:");
cs.matrice(b);
Console.WriteLine("Matrices entered are:");
cs.arrange(a);
Console.WriteLine();
cs.arrange(b);
Console.WriteLine("Addition of Two Matrices is:");
cs.addition(a,b);
}
else
{
Console.WriteLine("Addition is not Possible");
}
Console.ReadLine();
}
public void matrice(int [,]c)
{
for(int i=0;i<=k-1;i++)
{
for(int j=0;j<=l-1;j++)
{
c[i,j]=int.Parse(Console.ReadLine());
}
}
}
public void arrange(int [,]c)
{
for(int i=0;i<=k-1;i++)
{
for(int j=0;j<=l-1;j++)
{
Console.Write(c[i,j]+"\t");
}
Console.WriteLine();
}
}
public void addition(int [,]c,int [,]d)
{
for(int i=0;i<=k-1;i++)
{
for(int j=0;j<=l-1;j++)
{
Console.Write((c[i,j]+d[i,j])+"\t");
}
Console.WriteLine();
}
}
}
}
On this topic
Optimize Your Computer by Cleaning It Up
How to Remember Not to Wear that Next Week
From the Dream of Democracy to the Reality of Dictatorship
Multitasking Technologies
using System;
namespace AdditionOfTwoMatrices
{
///
/// Summary description for Class1.
///
class Class1
{
public static int k=0,l=0,m=0,n=0;
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
int [,]a=new int[10,10];
int [,]b=new int[10,10];
int [,]c=new int[10,10];
int [,]d=new int[10,10];
Class1 cs=new Class1();
Console.Write("Enter the order of First Matric : ");
k=int.Parse(Console.ReadLine());
Console.Write("- ");
m=int.Parse(Console.ReadLine());
Console.WriteLine();
Console.Write("Enter the order of Second Matric : ");
l=int.Parse( Console.ReadLine());
Console.Write("- ");
n=int.Parse(Console.ReadLine());
if(l==k && m==n)
{
Console.WriteLine("\nEnter The value of First Matrice:");
cs.matrice(a);
Console.WriteLine("Enter The value of Second Matrice:");
cs.matrice(b);
Console.WriteLine("Matrices entered are:");
cs.arrange(a);
Console.WriteLine();
cs.arrange(b);
Console.WriteLine("Addition of Two Matrices is:");
cs.addition(a,b);
}
else
{
Console.WriteLine("Addition is not Possible");
}
Console.ReadLine();
}
public void matrice(int [,]c)
{
for(int i=0;i<=k-1;i++)
{
for(int j=0;j<=l-1;j++)
{
c[i,j]=int.Parse(Console.ReadLine());
}
}
}
public void arrange(int [,]c)
{
for(int i=0;i<=k-1;i++)
{
for(int j=0;j<=l-1;j++)
{
Console.Write(c[i,j]+"\t");
}
Console.WriteLine();
}
}
public void addition(int [,]c,int [,]d)
{
for(int i=0;i<=k-1;i++)
{
for(int j=0;j<=l-1;j++)
{
Console.Write((c[i,j]+d[i,j])+"\t");
}
Console.WriteLine();
}
}
}
}





