Check if given four integers (or sides) make rectangle - GeeksforGeeks

31 May, 2021
Given four positive integers, determine if there’s a rectangle such that the lengths of its sides are a, b, c and d (in any order).Examples :  
Input : 1 1 2 2
Output : Yes

Input : 1 2 3 4
Output : No
Approach 1 :- We will check, if any of the two integers are equal and make sure rest of two are also equal using few if else conditions.  
C++
Java
Python3
C#
Javascript
// A simple program to find if given 4// values can represent 4 sides of rectangle#include <iostream>using namespace std; // Function to check if the given// integers value make a rectanglebool isRectangle(int a, int b, int c, int d){    // Square is also a rectangle    if (a == b == c == d)        return true;     else if (a == b && c == d)        return true;    else if (a == d && c == b)        return true;    else if (a == c && d == b)        return true;    else        return false;} // Driver codeint main(){    int a, b, c, d;    a = 1, b = 2, c = 3, d = 4;    if (isRectangle(a, b, c, d))        cout << "Yes";    else        cout << "No";    return 0;}
// A simple program to find if// given 4 values can represent// 4 sides of rectangleclass GFG {     // Function to check if the given    // integers value make a rectangle    static boolean isRectangle(int a, int b,                               int c, int d)    {        // Square is also a rectangle        if (a == b && a == c &&            a == d && c == d &&            b == c && b == d)            return true;             else if (a == b && c == d)            return true;        else if (a == d && c == b)            return true;        else if (a == c && d == b)            return true;        else            return false;    }         // Driver code    public static void main(String[] args)    {                 int a = 1, b = 2, c = 3, d = 4;        if (isRectangle(a, b, c, d))            System.out.println("Yes");        else            System.out.println("No");    }} // This code is contributed by prerna saini.
# A simple program to find if given 4# values can represent 4 sides of rectangle # Function to check if the given# integers value make a rectangledef isRectangle(a, b, c, d):         # check all sides of rectangle combinations    if (a==b and d==c) or (a==c and b==d) or (a==d and b==c):        return True    else:               return False  # Driver codea, b, c, d = 1, 2, 3, 4print("Yes" if isRectangle(a, b, c, d) else "No")  # This code is contributed by Jatinder SIngh
// A simple program to find if// given 4 values can represent// 4 sides of rectangleusing System; class GFG {     // Function to check if the given    // integers value make a rectangle    static bool isRectangle(int a, int b,                            int c, int d)    {        // Square is also a rectangle        if (a == b && a == c && a == d &&            c == d && b == c && b == d)            return true;         else if (a == b && c == d)            return true;                     else if (a == d && c == b)            return true;                     else if (a == c && d == b)            return true;                     else            return false;    }     // Driver code    public static void Main()    {         int a = 1, b = 2, c = 3, d = 4;        if (isRectangle(a, b, c, d))            Console.WriteLine("Yes");        else            Console.WriteLine("No");    }} // This code is contributed by vt_m.
<script> // A simple program to find if// given 4 values can represent// 4 sides of rectangle     // Function to check if the given    // integers value make a rectangle    function isRectangle(a, b, c, d)    {        // Square is also a rectangle        if (a == b && a == c &&            a == d && c == d &&            b == c && b == d)            return true;              else if (a == b && c == d)            return true;        else if (a == d && c == b)            return true;        else if (a == c && d == b)            return true;        else            return false;    } // Driver code         let a = 1, b = 2, c = 3, d = 4;        if (isRectangle(a, b, c, d))            document.write("Yes");        else            document.write("No");            </script>
Output : 
No
 
Aditya raj 9
Smitha Dinesh Semwal
satyamroy36
susmitakundugoaldanga
jatindersingh0607
Bitwise-XOR
square-rectangle
Bit Magic
Geometric
Bit Magic
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Little and Big Endian Mystery
Cyclic Redundancy Check and Modulo-2 Division
Binary representation of a given number
Add two numbers without using arithmetic operators
Set, Clear and Toggle a given bit of a number in C
How to check if a given point lies inside or outside a polygon?
Closest Pair of Points using Divide and Conquer algorithm
Program for distance between two points on earth
How to check if two given line segments intersect?
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)