Editorial Staff - - C Sharp Tutorial
If you are a c# beginner or want to start learning the c# programming language, then this program will help you to understand the basics of c# programming. In this program, we are going to share C# program to interchange any 2 columns of matrix with the output.
To increase your C# knowledge, practice all C sharp programs:
Copy the below c# program and execute it in your Microsoft Visual Studio IDE (Integrated Development Environment ). At the end of this program, I have shared the output program.
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(); } } |
Editorial Staff at FreeWebMentor is a team of professional developers leads by Prem Tiwari View all posts by Editorial Staff