Check if a triangle of positive area is possible with the given angles - GeeksforGeeks

25 Mar, 2021
Given three angles. The task is to check if it is possible to have a triangle of positive area with these angles. If it is possible print “YES” else print “NO”.Examples:  
Input : ang1 = 50, ang2 = 60, ang3 = 70 
Output : YES

Input : ang1 = 50, ang2 = 65, ang3 = 80
Output : NO
 
Approach: We can form a valid triangle if the below conditions satisfies:  
The sum of the three given angles equals to 180.
The sum of any two angles is greater than equal to the third one.
None of the given angles is zero.
Below is the implementation of the above approach:  
C++
Java
Python
C#
PHP
Javascript
// C++ program to check if a triangle// of positive area is possible with// the given angles#include <bits/stdc++.h>using namespace std; string isTriangleExists(int a, int b, int c){    // Checking if the sum of three    // angles is 180 and none of    // the angles is zero    if(a != 0 && b != 0 && c != 0 && (a + b + c)== 180)        // Checking if sum of any two angles        // is greater than equal to the third one        if((a + b)>= c || (b + c)>= a || (a + c)>= b)            return "YES";        else            return "NO";    else        return "NO";}// Driver Codeint main(){int a=50, b=60, c = 70;cout << isTriangleExists(a, b, c) << endl;return 0;}// This code is contributed by mits
// Java program to check if a triangle// of positive area is possible with// the given angles class GFG{static String isTriangleExists(int a, int b, int c){    // Checking if the sum of three    // angles is 180 and none of    // the angles is zero    if(a != 0 && b != 0 && c != 0 && (a + b + c)== 180)        // Checking if sum of any two angles        // is greater than equal to the third one        if((a + b)>= c || (b + c)>= a || (a + c)>= b)            return "YES";        else            return "NO";    else        return "NO";}// Driver Codepublic static void main(String[] args){int a=50, b=60, c = 70;System.out.println(isTriangleExists(a, b, c));}}// This code is contributed by mits
# Python program to check if a triangle# of positive area is possible with# the given angles def isTriangleExists(a, b, c):    # Checking if the sum of three    # angles is 180 and none of    # the angles is zero    if(a != 0 and b != 0 and c != 0 and (a + b + c)== 180):        # Checking if sum of any two angles        # is greater than equal to the third one        if((a + b)>= c or (b + c)>= a or (a + c)>= b):            return "YES"        else:            return "NO"    else:        return "NO" # Driver Codea, b, c = 50, 60, 70 print(isTriangleExists(50, 60, 70))
// C# program to check if a triangle// of positive area is possible with// the given anglesclass GFG{static string isTriangleExists(int a,                               int b,                               int c){    // Checking if the sum of three    // angles is 180 and none of    // the angles is zero    if(a != 0 && b != 0 &&       c != 0 && (a + b + c) == 180)                // Checking if sum of any two        // angles is greater than equal        // to the third one        if((a + b) >= c || (b + c) >= a ||                           (a + c) >= b)            return "YES";        else            return "NO";    else        return "NO";} // Driver Codestatic void Main(){    int a = 50, b = 60, c = 70;    System.Console.WriteLine(isTriangleExists(a, b, c));}} // This code is contributed by mits
<?php// PHP program to check if a triangle// of positive area is possible with// the given angles function isTriangleExists($a, $b, $c){    // Checking if the sum of three    // angles is 180 and none of    // the angles is zero    if($a != 0 && $b != 0 &&       $c != 0 && ($a + $b + $c) == 180)                // Checking if sum of any two        // angles is greater than equal        // to the third one        if(($a + $b)>= $c ||           ($b + $c)>= $a || ($a + $c)>= $b)            return "YES";        else            return "NO";    else        return "NO";} // Driver Code$a = 50;$b = 60;$c = 70;echo isTriangleExists($a, $b, $c); // This code is contributed by mits?>
<script>// javascript program to check if a triangle// of positive area is possible with// the given angles   function isTriangleExists(a , b , c){         // Checking if the sum of three        // angles is 180 and none of        // the angles is zero        if (a != 0 && b != 0 && c != 0 && (a + b + c) == 180)                     // Checking if sum of any two angles            // is greater than equal to the third one            if ((a + b) >= c || (b + c) >= a || (a + c) >= b)                return "YES";            else                return "NO";        else            return "NO";    }     // Driver Code    var a = 50, b = 60, c = 70;    document.write(isTriangleExists(a, b, c)); // This code is contributed by Rajput-Ji</script>
YES
 
Mithun Kumar
Rajput-Ji
Mathematical
Python
Python Programs
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Program to find GCD or HCF of two numbers
Modulo Operator (%) in C/C++ with Examples
Merge two sorted arrays
Prime Numbers
Program to find sum of elements in a given array
Read JSON file using Python
Adding new column to existing DataFrame in Pandas
Python map() function
How to get column names in Pandas dataframe