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 a C# program For A Boolean Matrix Question with the output.
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 69 70 71 72 73 74 75 76 |
using System; class BooleanMatrixQuestion { public static void modifyMatrix(int [,]mat, int R, int C) { int []row = new int [R]; int []col = new int [C]; int i, j; for (i = 0; i < R; i++) { row[i] = 0; } for (i = 0; i < C; i++) { col[i] = 0; } for (i = 0; i < R; i++) { for (j = 0; j < C; j++) { if (mat[i, j] == 1) { row[i] = 1; col[j] = 1; } } } for (i = 0; i < R; i++) { for (j = 0; j < C; j++) { if (row[i] == 1 || col[j] == 1) { mat[i, j] = 1; } } } } public static void printMatrix(int [,]mat, int R, int C) { int i, j; for (i = 0; i < R; i++) { for (j = 0; j < C; j++) { Console.Write(mat[i, j] + " "); } Console.WriteLine(); } } static public void Main () { int [,]mat = {{1, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 0, 0}}; Console.WriteLine("Matrix Intially"); printMatrix(mat, 3, 4); modifyMatrix(mat, 3, 4); Console.WriteLine("Matrix after "+ "modification n"); printMatrix(mat, 3, 4); } } |
Input Matrix
1 0 0 1
0 0 1 0
0 0 0 0
Matrix after modification
1 1 1 1
1 1 1 1
1 0 1 1
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.