# Valid Triangles Codechef Solution

#### ByBrokenprogrammers

Dec 6, 2022

Hello Programmers In this post, you will know how to solve the Valid Triangles Codechef Solution.

One more thing to add, donâ€™t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

### Problem

Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degrees.

### Input

The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three angles A, B and C, of the triangle separated by space.

### Output

For each test case, display ‘YES’ if the triangle is valid, and ‘NO’, if it is not, in a new line.

### Constraints

• 1 <= T <= 1000
• 1 <= A, B, C <= 180

Input:

```3
40 40 100
45 45 90
180 1 1
```

Output:

```YES
YES
NO```

### Valid Triangles CodeChef Solutions in Python

```T = int(input())
while T > 0:
a, b, c = map(int, input().split())
sum = a + b + c
if (sum == 180):
print("YES")
else:
print("NO")
T = T - 1    ```

### Valid Triangles CodeChef Solutions in CPP

```#include <iostream>
using namespace std;
int main(){
int a;
cin >> a;
while(a--){
int b,c,d;
cin >> b >> c >> d;
if(d==0 || b==0 || c==0 || b+c+d!=180)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}```

### Valid Triangles CodeChef Solutions in JAVA

```import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int tc = 0; tc < T; tc++) {
int A = sc.nextInt();
int B = sc.nextInt();
int C = sc.nextInt();
System.out.println(solve(A, B, C) ? "YES" : "NO");
}
sc.close();
}
static boolean solve(int A, int B, int C) {
return A + B + C == 180;
}
}```

Disclaimer:  The above Problem (Valid Triangles) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.