Codechef Problems: Triangle Checking (TRICHECK)
Problem Statement:
Solution:
Given,
A, B, C - Side-length of a triangle
to find - whether they are sides of a valid non-degenerate triangle
It is given in the problem statement that to be sides of non-degenerate triangle, A, B, C be sides of triangle must hold 3 conditions:
A + B > C
B + C > A
A + C > B
so the possibilities
condition 1 : all three conditions hold
output : Yes
condition 2 : otherwise
output : No
Code Solution:
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a + b > c && b + c > a && a + c > b) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
Comments
Post a Comment