Check whether Quadrilateral is valid or not if angles are given - GeeksforGeeks

01 Sep, 2021
Given four integers A, B, C and D which represents the four angles of a Quadrilateral in degrees. The task is to check whether the given quadrilateral is valid or not.
Examples: 
Input: A = 80, B = 70, C = 100, D=110 Output: Valid 
Input: A = 70, B = 80, C = 130, D=60 Output: Invalid  
Approach: A Quadrilateral is valid if the sum of the four angles is equal to 360 degrees.
Below is the implementation of the above approach:  
C++
Java
Python3
C#
PHP
Javascript
// C++ program to check if a given// quadrilateral is valid or not#include <bits/stdc++.h>using namespace std; // Function to check if a given// quadrilateral is valid or notbool Valid(int a, int b, int c, int d){    // Check condition    if (a + b + c + d == 360)        return true;         return false;} // Driver codeint main(){    int a = 80, b = 70, c = 100, d = 110;     if (Valid(a, b, c, d))        cout << "Valid quadrilateral";    else        cout << "Invalid quadrilateral";             return 0;}
// Java program to check if a given// quadrilateral is valid or notclass GFG{     // Function to check if a given// quadrilateral is valid or notpublic static int Valid(int a, int b,                        int c, int d){    // Check condition    if (a + b + c + d == 360)        return 1;         return 0;} // Driver codepublic static void main (String[] args){    int a = 80, b = 70, c = 100, d = 110;         if (Valid(a, b, c, d) == 1)        System.out.println("Valid quadrilateral");    else        System.out.println("Invalid quadrilateral");}} // This code is contributed// by apurva_sharma244
# Python program to check if a given# quadrilateral is valid or not # Function to check if a given# quadrilateral is valid or notdef Valid(a, b, c, d):     # Check condition    if (a + b + c + d == 360):        return True;         return False;  # Driver codea = 80; b = 70; c = 100; d = 110; if (Valid(a, b, c, d)):    print("Valid quadrilateral");else:    print("Invalid quadrilateral"); # This code is contributed by Rajput-Ji
// C# program to check if a given// quadrilateral is valid or not class GFG{ // Function to check if a given// quadrilateral is valid or notstatic bool Valid(int a, int b,                  int c, int d){    // Check condition    if (a + b + c + d == 360)        return true;         return false;} // Driver codepublic static void Main(){    int a = 80, b = 70, c = 100, d = 110;         if (Valid(a, b, c, d))        Console.WriteLine("Valid quadrilateral");    else        Console.WriteLine("Invalid quadrilateral");}} // This code is contributed by nidhiva
<?php// PHP program to check if a given// quadrilateral is valid or not // Function to check if a given// quadrilateral is valid or notfunction Valid($a, $b, $c, $d){    // Check condition    if ($a + $b + $c + $d == 360)        return true;         return false;} // Driver Code$a = 80;$b = 70;$c = 100;$d = 110; if (Valid($a, $b, $c, $d))    echo("Valid quadrilateral");else    echo("Invalid quadrilateral"); // This code is contributed by Naman_garg.?>
<script> // Javascript program to check if a given// quadrilateral is valid or not // Function to check if a given// quadrilateral is valid or notfunction Valid(a, b, c, d){         // Check condition    if (a + b + c + d == 360)        return 1;         return 0;} // Driver codevar a = 80, b = 70, c = 100, d = 110;     if (Valid(a, b, c, d) == 1)    document.write("Valid quadrilateral");else    document.write("Invalid quadrilateral");     // This code is contributed by Khushboogoyal499 </script>
Valid quadrilateral
nidhiva
apurva_sharma244
Rajput-Ji
Naman_Garg
khushboogoyal499
clintra
rajeev0719singh
school-programming
C++ Programs
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Passing a function as a parameter in C++
Program to implement Singly Linked List in C++ using class
Const keyword in C++
cout in C++
Handling the Divide by Zero Exception in C++
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?
How to check if a given point lies inside or outside a polygon?
Convex Hull | Set 1 (Jarvis's Algorithm or Wrapping)