hamzajaved

Addition Of Matrix in C#

Oct 3rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             int[,] a = new int[10,10];
  6.             int[,] b = new int[10,10];
  7.             int[,] c = new int[10,10];
  8.  
  9.             int m, n;
  10.             Console.WriteLine("Enter the Number of rows and coulmns of Matrix A and B");
  11.             m = Convert.ToInt16(Console.ReadLine());
  12.             n = Convert.ToInt16(Console.ReadLine());
  13.             //Getting The Values of Matrix A
  14.             Console.WriteLine("Enter the values of Matrix A");
  15.             for (int i = 0; i < m; i++)
  16.             {
  17.                 for (int j = 0; j < n; j++)
  18.                 {
  19.                     a[i, j] = Convert.ToInt16(Console.ReadLine());
  20.                 }
  21.             }
  22.             //Getting The Values of Matrix B
  23.             Console.WriteLine("Enter the values of Matrix B");
  24.             for (int i = 0; i < m; i++)
  25.             {
  26.                 for (int j = 0; j < n; j++)
  27.                 {
  28.                     b[i, j] = Convert.ToInt16(Console.ReadLine());
  29.                 }
  30.             }
  31.             //Printing Matrix A
  32.             Console.WriteLine("Matrix A");
  33.             for (int i = 0; i < m; i++)
  34.             {
  35.                 for (int j = 0; j < n; j++)
  36.                 {
  37.  
  38.                     Console.Write(a[i, j] + "\t");
  39.  
  40.                 }
  41.                 Console.WriteLine();
  42.             }
  43.             Console.WriteLine("Matrix B");
  44.             //Printing Matrix B
  45.             for (int i = 0; i < m; i++)
  46.             {
  47.                 for (int j = 0; j < n; j++)
  48.                 {
  49.                     Console.Write(b[i,j] + "\t");
  50.                 }
  51.                 Console.WriteLine();
  52.             }
  53.  
  54.             //Addition Of Matrix
  55.             Console.WriteLine("Addition Of Matrix");
  56.             for (int i = 0; i < m; i++)
  57.             {
  58.                 for (int j = 0; j < n; j++)
  59.                 {
  60.                     c[i, j] = a[i, j] + b[i, j];
  61.                     Console.Write(c[i,j] + "\t");
  62.  
  63.                 }
  64.                 Console.WriteLine("\n");
  65.  
  66.             }
  67.  
  68.  
  69.         }
  70.     }
Add Comment
Please, Sign In to add comment