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

27 Apr, 2021
Given three integers A, B and C which are the three angles of a possible triangle in degrees, the task is to check whether the triangle is valid or not.Examples:  
Input: A = 60, B = 40, C = 80 Output: ValidInput: A = 55, B = 45, C = 60 Output: Invalid  
 
Approach: A triangle is valid if the sum of the three angles is equal to 180 degrees.  
Below is the implementation of the above approach:  
C++
Java
Python3
C#
Javascript
// C++ implementation of the approach#include <bits/stdc++.h>using namespace std; // Function to check if sum of the// three angles is 180 or notbool 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 codeint main(){    int a = 60, b = 40, c = 80;     if (Valid(a, b, c))        cout << "Valid";    else        cout << "Invalid";}
// Java program to check// validity of any triangleclass 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 implementation of the approach # Function to check if sum of the# three angles is 180 or notdef 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 codeif __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# program to check// validity of any triangleusing 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 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.  
Output:
Valid
apurva_sharma244
vt_m
sanjeev2552
DivyanshuGupta2
bunnyram19
school-programming
triangle
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Equation of circle when three points on the circle are given
Convex Hull using Divide and Conquer Algorithm
Circle and Lattice Points
Orientation of 3 ordered points
Check if a line touches or intersects a circle
Program for Fibonacci numbers
Write a program to print all permutations of a given string
C++ Data Types
Set in C++ Standard Template Library (STL)
Program to find GCD or HCF of two numbers