#K47087. Matrix Rank Calculation
Matrix Rank Calculation
Matrix Rank Calculation
You are given a matrix A with n rows and m columns. Your task is to compute its rank. The rank of a matrix, denoted by \(\operatorname{rank}(A)\), is defined as the maximum number of linearly independent rows (or, equivalently, columns) of the matrix. In other words, it is the dimension of the row space (or column space) of A.
You can use any method (such as Gaussian elimination) to find the rank. Make sure to handle cases where some rows or columns are all zeros.
inputFormat
The first line contains two integers n
and m
separated by a space, where n
is the number of rows and m
is the number of columns in the matrix.
The next n
lines each contain m
space-separated integers representing the elements of the matrix.
outputFormat
Output a single integer representing the rank of the given matrix.
## sample3 3
10 20 10
-20 -30 10
30 50 0
2