📜  检查四边形是否有效,如果给出了角度

📅  最后修改于: 2021-05-04 23:52:11             🧑  作者: Mango

给定四个整数ABCD ,它们表示一个四边形的四个角度(以度为单位)。任务是检查给定的四边形是否有效。

例子:

方法:
如果四个角度之和等于360度,则四边形有效。

下面是上述方法的实现:

C++
// C++ program to check if a given 
// quadilateral is valid or not
#include 
using namespace std;
  
// Function to check if a given 
// quadilateral is valid or not
bool Valid(int a, int b, int c, int d)
{
    // Check condition
    if (a + b + c + d == 360)
        return true;
      
    return false;
}
  
// Driver code
int main()
{
    int a = 80, b = 70, c = 100, d = 110;
  
    if (Valid(a, b, c, d))
        cout << "Valid quadilateral";
    else
        cout << "Invalid quadilateral";
          
    return 0;
}


Java
// Java program to check if a given 
// quadilateral is valid or not 
class GFG
{
      
// Function to check if a given 
// quadilateral 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 quadilateral"); 
    else
        System.out.println("Invalid quadilateral"); 
} 
}
  
// This code is contributed
// by apurva_sharma244


Python3
# Python program to check if a given 
# quadilateral is valid or not
  
# Function to check if a given 
# quadilateral is valid or not
def 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)):
    print("Valid quadilateral");
else:
    print("Invalid quadilateral");
  
# This code is contributed by Rajput-Ji


C#
// C# program to check if a given 
// quadilateral is valid or not  
class GFG 
{
  
// Function to check if a given 
// quadilateral 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 quadilateral"); 
    else
        Console.WriteLine("Invalid quadilateral"); 
} 
}
  
// This code is contributed by nidhiva


PHP


输出:
Valid quadilateral