Question: Program to check whether the matrix is row matrix or columns matrix or the square matrix.
Row Matrix: A matrix is said to be row matrix if it has only one row. A matrix of order 1 x n is the row matrix.
For example:
Column Matrix : A matrix is said to be column matrix if it has only one column. A matrix of order m x 1 is the column matrix.
For example:
Square Matrix: A matrix in which the no. of row is equals to the no. of column is said to be a Square matrix. Thus an m x n matrix is said to be square matrix if m = n and is known as square matrix of order n.
For example:
Code Snippet:
Read also:
Zero matrix in C#
Diagonal Matrix in C#.
Pattern programming in C#
Row Matrix: A matrix is said to be row matrix if it has only one row. A matrix of order 1 x n is the row matrix.
For example:
Column Matrix : A matrix is said to be column matrix if it has only one column. A matrix of order m x 1 is the column matrix.
For example:
Square Matrix: A matrix in which the no. of row is equals to the no. of column is said to be a Square matrix. Thus an m x n matrix is said to be square matrix if m = n and is known as square matrix of order n.
For example:
Code Snippet:
- using System;
- public class MatType
- {
- public static void Main()
- {
- int row, col;
- int[,] matA = new int[10,10];
- Console.Write("Enter the Row: ");
- row = Convert.ToInt32(Console.ReadLine());
- Console.Write("Enter the Col: ");
- col = Convert.ToInt32(Console.ReadLine());
- if(row == 1)
- {
- Console.WriteLine("It is a Row matrix.");
- }
- else if(col == 1)
- {
- Console.WriteLine("It is a Column matrix.");
- }
- else if(row == col)
- {
- Console.WriteLine("It is a Square matrix.");
- }
- else
- {
- Console.WriteLine("The given matrix is the simple matrix.");
- }
- Console.WriteLine("The matrix is: ");
- for(int i = 1; i<=row; i++)
- {
- for(int j= 1 ; j<=col; j++)
- {
- Console.Write("Matrix A[{0},{1}]", i, j);
- matA[i,j] = Convert.ToInt32(Console.ReadLine());
- }
- Console.WriteLine();
- }
- for(int i = 1; i<=row; i++)
- {
- for(int j= 1 ; j<=col; j++)
- {
- Console.Write("{0} ", matA[i,j]);
- }
- Console.WriteLine();
- }
- Console.ReadLine();
- }
- }
** Complete code
Description:
In the above code we simply check the condition for row matrix, column matrix and square matrix from line 14 to 29.
Screenshot of Output:
Read also:
Zero matrix in C#
Diagonal Matrix in C#.
Pattern programming in C#