Program to check if a rectangle is a square or not Last Updated : 08 Aug, 2024 Comments Improve Suggest changes Like Article Like Report 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: SquareExplanation: Since the length and breadth of the rectangle is same, therefore the given rectangle is a square.Input: Length = 6, Breadth = 8Output: RectangleExplanation: 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: C++ #include <iostream> using namespace std; int main() { int length, breadth; // Example test case length = 5; breadth = 5; if (length == breadth) cout << "Square" << endl; else cout << "Not a Square" << endl; return 0; } C #include <stdio.h> int main() { int length, breadth; // Example test case length = 5; breadth = 5; if (length == breadth) printf("Square.\n"); else printf("Not a Square.\n"); return 0; } Java public class SquareChecker { public static void main(String[] args) { // Example test case int length = 5; int breadth = 5; if (length == breadth) System.out.println("Square."); else System.out.println("Not a Square."); } } Python # Example test case length, breadth = 5, 5 if length == breadth: print("Square.") else: print("Not a Square.") C# using System; class Program { static void Main() { // Example test case int length = 5; int breadth = 5; if (length == breadth) Console.WriteLine("Square."); else Console.WriteLine("Not a Square."); } } JavaScript // Example test case let length = 5; let breadth = 5; if (length === breadth) console.log("Square."); else console.log("Not a Square."); OutputSquare Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program to check if a rectangle is a square or not C code_r Follow Improve Article Tags : DSA Similar Reads Program to find Perimeter / Circumference of Square and Rectangle The circumference of a figure is the sum of all the side lengths. To calculate the circumference of square, length of one of the side is required as all sides are equal. To calculate the circumference of rectangle, length and breadth of rectangle is required. Circumference of a Square:  The circumf 5 min read Check if a point lies inside a rectangle | Set-2 Given coordinates of bottom-left and top-right corners of a rectangle. Check if a point (x, y) lies inside this rectangle or not. Examples: Input: bottom-left: (0, 0), top-right: (10, 8), point: (1, 5) Output: Yes Input: bottom-left: (-1, 4), top-right:(2, 3), point:(0, 4) Output: No This problem is 6 min read Check whether a given point lies inside a rectangle or not Given four points of a rectangle, and one more point P. Write a function to check whether P lies within the given rectangle or not.Examples:  Input : R = [(10, 10), (10, -10), (-10, -10), (-10, 10)] P = (0, 0)Output : yesIllustration :Input : R = [(10, 10), (10, -10), (-10, -10), (-10, 10)], P = (20 14 min read Program to print a rectangle pattern Given height h and width w, print a rectangular pattern as shown in the example below. Examples: Input : h = 4, w = 5 Output : @@@@@ @ @ @ @ @@@@@ Input : h = 7, w = 9 Output : @@@@@@@@ @ @ @ @ @ @ @ @ @ @ @@@@@@@@ The idea is to run two loops. One for the number of rows to be printed and the other 4 min read Program to calculate the length of the diagonal in a rectangle Write a program to calculate the length of the diagonal in a rectangle with the given length and breadth. Examples: Input: Length = 5, Width = 3Output: Diagonal Length = 5.83095 Input: Length = 8, Width = 6Output: Diagonal Length = 10 Approach: To solve the problem, follow the below idea: The diagon 2 min read Like