Ticker

6/recent/ticker-posts

Triangle With Angle with Solution

 



Triangle With Angle:

Problem Description:

You're given the three angles ab, and c respectively. Now check if these three angles can form a valid triangle with an area greater than 0 or not. Print "YES"(without quotes) if it can form a valid triangle with an area greater than 0, otherwise print "NO" (without quotes).

Input:

·       First-line will contain three numbers ab, and c separated by space.

Output:

Print "YES"(without quotes) if these sides can form a valid triangle, otherwise, print "NO" (without quotes).

Constraints

·       0≤a,b,c≤180

Sample Input 1:

            20 40 120

Sample Output 1:

            YES

Sample Input 2:

            100 18 42

Sample Output 2:

            NO

EXPLANATION:

·       In the first example, angles set (20, 40, 120) can form a triangle with an area greater than 0.

·       In the second example, angles set (100, 18, 42) will never form a valid triangle.


Solution:

C++:

#include <iostream>
using namespace std;

int main()
{
    int abc;
    cin >> a >> b >> c;
    if ((a + b + c) == 180 && a > 0 && b > 0 && c > 0)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}



Don't forget to share this post.


Post a Comment

2 Comments

  1. sir ye a>0 b>0 c>0 kyo likha hai
    hame to area find karna hai vo check karna hai ki vo greater than 0 ho

    ReplyDelete
    Replies
    1. Logic to check triangle validity if angles are given

      Take angles from users and store in variables say a, b, c.
      Now,
      Check if(a+b+c == 180) then, triangle can be formed otherwise not.

      Note- *** In addition, make sure angles are greater than 0 i.e. check condition for angles if(angle1 > 0 && angle2 > 0 && angle3 > 0).

      angles 0 se greater hona chahiye isley check kiya hai aur sum of angles 180 hona chahiye tabhi triangle valid hoga .
      i hope you understand.

      Delete