Program to find all types of Matrix

Given the dimension of the matrix R(rows) * C(column) the task is to find which type of matrix is representing by the given dimension.

Examples:

Input : R = 1 C = 0
Output : Row Matrix 

Input : R = 4 C = 5
Output : Horizontal Matrix 
  • Row Matrix : When R = 1 and C = 0 then the matrix represent Row Matrix .
  • Column Matrix : When C = 1 and R = 0 then the matrix represent Column Matrix.
  • Horizontal Matrix : A Matrix in which number of rows is smaller than the number of column is called Horizontal Matrix (R < C) .
  • Vertical Matrix : A Matrix in which number of rows is greater than the number of column is called Horizontal Matrix (R > C).
  • Square Matrix : A matrix in which number of rows is equal to number of column is called Square Matrix (R = C).

C++

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to check 
// types of Matrix
#include <bits/stdc++.h>
using namespace std;
  
// Fuction to display which 
// type of matrix
void check(int r, int c)
{
    if (r == 0 && c == 1)
        cout << "Column Matrix " << endl;
    else if (r == 1 && c == 0)
        cout << "Row Matrix " << endl;
    else if (r < c)
        cout << "Horizontal Matrix " << endl;
    else if (r > c)
        cout << "Vertical Matrix " << endl;
    else if (r == c)
        cout << "Square Matrix " << endl;
}
  
// Driver code
int main()
{
    // input for r and c
    // function calling
    check(1, 0);
    check(0, 1);
    check(4, 5);
    check(5, 4);
    check(3, 3);
      
    return 0;
}

chevron_right


Java

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to check 
// types of Matrix
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.regex.*;
  
public class GFG {
  
    // Fuction to display which type of matrix
    static void check(int r, int c)
    {
        if (r == 0 && c == 1)
            System.out.println("Column Matrix ");
        else if (r == 1 && c == 0)
            System.out.println("Row Matrix ");
        else if (r < c)
            System.out.println("Horizontal Matrix ");
        else if (r > c)
            System.out.println("Vertical Matrix ");
        else if (r == c)
            System.out.println("Square Matrix ");
    }
  
    // Driver code
    public static void main(String[] args) 
    {
  
        // static input for r and c
        // function calling
        check(1, 0);
        check(0, 1);
        check(4, 5);
        check(5, 4);
        check(3, 3);
    }
}

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to check
# types of Matrix
  
  
# Fuction to display which 
# type of matrix
def check(r, c) :
      
  
    if r == 0 and c == 1:
        print ("Column Matrix ")
          
    elif r == 1 and c == 0:
        print ("Row Matrix "
      
    elif r < c:
        print ("Horizontal Matrix "
          
    elif r > c:
        print ("Vertical Matrix "
          
    elif r == c:
        print ("Square Matrix "
  
  
# Driver code
check(1, 0)
check(0, 1)
check(4, 5)
check(5, 4)
check(3, 3)
  
# This code is contributed by Sam007.
     

chevron_right


C#

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to check types of Matrix
using System;
  
class GFG
{
    // Fuction to display which type of matrix
    static void check(int r, int c)
    {
        if (r == 0 && c == 1)
            Console.WriteLine("Column Matrix ");
        else if (r == 1 && c == 0)
            Console.WriteLine("Row Matrix ");
        else if (r < c)
            Console.WriteLine("Horizontal Matrix ");
        else if (r > c)
            Console.WriteLine("Vertical Matrix ");
        else if (r == c)
            Console.WriteLine("Square Matrix ");
    }
  
    // Driver code
    static void Main() 
    {
  
        // static input for r and c
        // function calling
        check(1, 0);
        check(0, 1);
        check(4, 5);
        check(5, 4);
        check(3, 3);
    }
      
}
  
// This code is contributed by Sam007.

chevron_right


PHP

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to check 
// types of Matrix
  
// Fuction to display which 
// type of matrix
function check($r, $c)
{
    if ($r == 0 && $c == 1)
        echo "Column Matrix "."\n";
    else if ($r == 1 && $c == 0)
        echo "Row Matrix "."\n";
    else if ($r < $c)
        echo "Horizontal Matrix "."\n";
    else if ($r > $c)
        echo "Vertical Matrix "."\n";
    else if ($r == $c)
        echo "Square Matrix "."\n";
}
  
    // Driver code
      
    // input for r and c
    // function calling
    check(1, 0);
    check(0, 1);
    check(4, 5);
    check(5, 4);
    check(3, 3); 
      
// This code is contributed by Sam007
?>

chevron_right



Output :

Row Matrix 
Column Matrix 
Horizontal Matrix 
Vertical Matrix 
Square Matrix


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : Sam007



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.