hamzajaved

Transpose Of Matrix in C#

Oct 3rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 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 m, n;
  8.             Console.WriteLine("Enter the rows and coulms of Matrix");
  9.             m = Convert.ToInt16(Console.ReadLine());
  10.             n = Convert.ToInt16(Console.ReadLine());
  11.  
  12.             Console.WriteLine("Enter the Values of Matrix");
  13.             for (int i = 0; i < m; i++)
  14.             {
  15.                 for (int j = 0; j < n; j++)
  16.                 {
  17.                     a[i,j] = Convert.ToInt16(Console.ReadLine());
  18.                 }
  19.                
  20.             }
  21.  
  22.             Console.WriteLine("Matrix A");
  23.             for (int i = 0; i < m; i++)
  24.             {
  25.                 for (int j = 0; j < n; j++)
  26.                 {
  27.                     Console.Write(a[i,j] + "\t");
  28.                 }
  29.                 Console.WriteLine();
  30.             }
  31.  
  32.             Console.WriteLine("Transpose Matrix");
  33.             for (int i = 0; i < m; i++)
  34.             {
  35.                 for (int j = 0; j < n; j++)
  36.                 {
  37.                     b[i, j] = a[j, i];
  38.                     Console.Write(b[i,j] + "\t");
  39.                 }
  40.                 Console.WriteLine();
  41.             }
  42.  
  43.         }
  44.     }
Add Comment
Please, Sign In to add comment