📜  如果给出角度,检查三角形是否有效

📅  最后修改于: 2021-10-23 09:11:53             🧑  作者: Mango

给定三个整数ABC ,它们是可能的三角形的三个角度(以度为单位),任务是检查三角形是否有效。
例子:

方法:如果三个角之和等于 180 度,则三角形有效。

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to check if sum of the
// three angles is 180 or not
bool Valid(int a, int b, int c)
{
    // Check condition
    if (a + b + c == 180 && a != 0 && b != 0 && c != 0)
        return true;
    else
        return false;
}
 
// Driver code
int main()
{
    int a = 60, b = 40, c = 80;
 
    if (Valid(a, b, c))
        cout << "Valid";
    else
        cout << "Invalid";
}


Java
// Java program to check
// validity of any triangle
class GFG {
 
    // Function to check if sum of the
    // three angles is 180 or not
    public static int Valid(int a, int b, int c)
    {
        // check condition
        if (a + b + c == 180 && a != 0 && b != 0 && c != 0)
            return 1;
        else
            return 0;
    }
 
    // Driver Code
    public static void main(String args[])
    {
 
        int a = 60, b = 40, c = 80;
 
        // function calling and print output
        if ((Valid(a, b, c)) == 1)
            System.out.print("Valid");
        else
            System.out.print("Invalid");
    }
}
 
// This code is contributed
// by Apurva Sharma


Python3
# Python3 implementation of the approach
 
# Function to check if sum of the
# three angles is 180 or not
def Valid(a, b, c):
 
    # Check condition
    if ((a + b + c == 180) and a != 0 and b != 0 and c != 0):
        return True
    else:
        return False
 
# Driver code
if __name__ == "__main__":
    a = 60
    b = 40
    c = 80
    if (Valid(a, b, c)):
        print("Valid")
    else:
        print("Invalid")
 
# This code is contributed by
# sanjeev2552


C#
// C# program to check
// validity of any triangle
using System;
 
class GFG {
 
    // Function to check if sum of the
    // three angles is 180 or not
    public static int Valid(int a, int b, int c)
    {
        // check condition
        if (a + b + c == 180 && a != 0 && b != 0 && c != 0)
            return 1;
        else
            return 0;
    }
 
    // Driver Code
    public static void Main()
    {
        int a = 60, b = 40, c = 80;
 
        // function calling and print output
        if ((Valid(a, b, c)) == 1)
            Console.WriteLine("Valid");
        else
            Console.WriteLine("Invalid");
    }
}
 
// This code is contributed
// by anuj_6


Javascript
// javascript program to check
// validity of any triangle
 
    // Function to check if sum of the
    // three angles is 180 or not
   function Valid(a,  b,  c)
    {
     
        // check condition
        if (a + b + c == 180 && a != 0 && b != 0 && c != 0)
            return 1;
        else
            return 0;
    }
   
    // Driver Code
        var a = 60, b = 40, c = 80;
   
        // function calling and print output
        if ((Valid(a, b, c)) == 1){
            document.write("Valid");
            }
        else{
            document.write("Invalid");
          }
     
// This code is contributed by bunnyram19.


输出:

Valid