Be the first user to complete this post
|
Add to List |
294. Find if Triangle can be formed using given 3 sides
Algorithms – Java Program to find if Triangle can be formed using given 3 sides
Objective- Given 3 side lengths, write a program to find out if using these 3 sides, a triangle can be formed.
Example:
Triangle can be formed using side 2.5, 3.5, 5.0 Triangle cannot be formed using side 1.0, 3.0, 5.0 Sum of 1.0 and 3.0 is not > 5.0
Approach:
- If sum of length of any two sides is strictly greater than the length of third side then triangle can be constructed, else we cannot construct a triangle.
- Say sides lengths given are- a, b, c then to form a triangle, a+b>c and b+c>a, a+c>b. If any of the condition is not true, triangle cannot be formed.
Output:
Triangle can be formed using side 2.5, 3.5, 5.0 _____________________ Sum of 1.0 and 3.0 is not > 5.0 Triangle cannot be formed using side 1.0, 3.0, 5.0