VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-check-if-a-rectangle-is-a-square-or-not/

⇱ Program to check if a rectangle is a square or not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to check if a rectangle is a square or not

Last Updated : 23 Jul, 2025

Given the dimensions of a rectangle (length and breadth), write a program to determine whether the given rectangle is a square or not.

Examples:

Input: Length = 5, Breadth = 5
Output: Square
Explanation: Since the length and breadth of the rectangle is same, therefore the given rectangle is a square.

Input: Length = 6, Breadth = 8
Output: Rectangle
Explanation: Since the length and breadth are different, therefore it is a rectangle.

Approach: To solve the problem, follow the below idea:

If the length and breadth of a rectangle are equal, it is a square. Otherwise, it is a rectangle.

Step-by-step algorithm:

  • Take the input for length and breadth.
  • Check if length equals breadth.
  • If true, print "Square." Otherwise, print "Not a Square."

Below is the implementation of the algorithm:


Output
Square

Time Complexity: O(1)
Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: