Check whether the triangle is valid or not if angles are given Last Updated : 04 Jun, 2022 Comments Improve Suggest changes Like Article Like Report 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++ // C++ implementation of the approach #include <bits/stdc++.h> 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. Output: Valid Time Complexity: O(1) Auxiliary Space: O(1) Comment More info A apurva_sharma244 Follow Improve Article Tags : Mathematical Geometric DSA triangle school-programming +1 More Explore DSA FundamentalsLogic Building Problems 2 min read Analysis of Algorithms 1 min read Data StructuresArray Data Structure 3 min read String in Data Structure 2 min read Hashing in Data Structure 2 min read Linked List Data Structure 2 min read Stack Data Structure 2 min read Queue Data Structure 2 min read Tree Data Structure 2 min read Graph Data Structure 3 min read Trie Data Structure 15+ min read AlgorithmsSearching Algorithms 2 min read Sorting Algorithms 3 min read Introduction to Recursion 14 min read Greedy Algorithms 3 min read Graph Algorithms 3 min read Dynamic Programming or DP 3 min read Bitwise Algorithms 4 min read AdvancedSegment Tree 2 min read Binary Indexed Tree or Fenwick Tree 15 min read Square Root (Sqrt) Decomposition Algorithm 15+ min read Binary Lifting 15+ min read Geometry 2 min read Interview PreparationInterview Corner 3 min read GfG160 3 min read Practice ProblemGeeksforGeeks Practice - Leading Online Coding Platform 6 min read Problem of The Day - Develop the Habit of Coding 5 min read Like