Check whether Quadrilateral is valid or not if angles are given

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++
// 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
// Java program to check if a given // quadrilateral is valid or not class GFG{     // Function to check if a given // quadrilateral is valid or not public static int Valid(int a, int b,                         int c, int d) {     // Check condition     if (a + b + c + d == 360)         return 1;          return 0; } Â
// Driver code public 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 |
Python3
# 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#
// C# program to check if a given // quadrilateral is valid or not class GFG {Â
// Function to check if a given // quadrilateral is valid or not static bool Valid(int a, int b,                   int c, int d) {     // Check condition     if (a + b + c + d == 360)         return true;          return false; } Â
// Driver code public 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 // PHP program to check if a given // quadrilateral is valid or not Â
// Function to check if a given // quadrilateral is valid or not function 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. ?> |
Javascript
<script>Â
// Javascript program to check if a given // quadrilateral is valid or not Â
// Function to check if a given // quadrilateral is valid or not function 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> |
Output
Valid quadrilateral
Time Complexity : O(1)
Auxiliary Space: O(1)
Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 zambiatek!




