If you are a python beginner and want to start learning the python programming, then keep your close attention in this tutorial as I am going to share a C# program to interchange any 2 columns of matrix.
To increase your Python knowledge, practice all Python programs:
Copy the below python program and execute it with the help of python compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; class interchangecol { int m, n; int[,] a; public interchangecol(int x, int y) { m = x; n = y; a = new int[m, n]; } public void readmatrix() { Console.WriteLine("Enter the Elements : "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { Console.WriteLine("a[{0},{1}] =", i, j); a[i, j] = Convert.ToInt32(Console.ReadLine()); } } } public void printmax() { Console.WriteLine("Given Matrix : "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { Console.Write("{0}\t", a[i, j]); } Console.WriteLine(); } } public void interchange() { Console.WriteLine("Enter the Column Number to Interchange : "); int i = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the Column Number with which Interchange is to be Accomplished :"); int j = Convert.ToInt32(Console.ReadLine()); for (int k = 0; k < m; k++) { int temp = a[k, i-1]; a[k, i-1] = a[k, j-1]; a[k, j-1] = temp; } } public static void Main() { int x, y; interchangecol obj; Console.Write("Enter the Number of Rows"); x = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter the Number of Columns"); y = Convert.ToInt32(Console.ReadLine()); obj = new interchangecol(x, y); obj.readmatrix(); obj.printmax(); obj.interchange(); obj.printmax(); Console.ReadLine(); } } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.