How to print a specific column of a matrix in C#

1 Answer

0 votes
using System;
 
public class PrintSpecificColumnOfMatrix_CSharp
{
    public static void printColumnOfMatrix(int[,] matrix, int col) {
        int rows = matrix.GetLength(0);
        
        for (int i = 0; i < rows; i++) {
            Console.Write(matrix[i, col] + " ");
        }
    }
 
    public static void Main(string[] args)
    {
        int[,] matrix = new int[,]
        {
            {3, 2, 5, 1},
            {4, 7, 6, 5},
            {9, 3, 0, 1}
        };
 
        printColumnOfMatrix(matrix, 1);
    }
}
 
 
 
/*
run:
   
2 7 3 
   
*/

 



answered Jul 12, 2024 by avibootz
edited Jul 13, 2024 by avibootz

Related questions

1 answer 66 views
1 answer 312 views
1 answer 59 views
1 answer 62 views
1 answer 51 views
...