Check whether Quadrilateral is valid or not if angles are given
Last Updated :
31 May, 2022
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++
#include <bits/stdc++.h>
using namespace std;
bool Valid( int a, int b, int c, int d)
{
if (a + b + c + d == 360)
return true ;
return false ;
}
int 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
class GFG
{
public static int Valid( int a, int b,
int c, int d)
{
if (a + b + c + d == 360 )
return 1 ;
return 0 ;
}
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" );
}
}
|
Python3
def Valid(a, b, c, d):
if (a + b + c + d = = 360 ):
return True ;
return False ;
a = 80 ; b = 70 ; c = 100 ; d = 110 ;
if (Valid(a, b, c, d)):
print ( "Valid quadrilateral" );
else :
print ( "Invalid quadrilateral" );
|
C#
class GFG
{
static bool Valid( int a, int b,
int c, int d)
{
if (a + b + c + d == 360)
return true ;
return false ;
}
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" );
}
}
|
PHP
<?php
function Valid( $a , $b , $c , $d )
{
if ( $a + $b + $c + $d == 360)
return true;
return false;
}
$a = 80;
$b = 70;
$c = 100;
$d = 110;
if (Valid( $a , $b , $c , $d ))
echo ( "Valid quadrilateral" );
else
echo ( "Invalid quadrilateral" );
?>
|
Javascript
<script>
function Valid(a, b, c, d)
{
if (a + b + c + d == 360)
return 1;
return 0;
}
var a = 80, b = 70, c = 100, d = 110;
if (Valid(a, b, c, d) == 1)
document.write( "Valid quadrilateral" );
else
document.write( "Invalid quadrilateral" );
</script>
|
Output
Valid quadrilateral
Time Complexity : O(1)
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...