+ 2

CHALLENGE: Third angle of triangle

You are given two angles (in degrees) of a triangle. Write a function to return the 3rd.

16th Nov 2017, 10:26 PM
Ilia Fedorov
Ilia Fedorov - avatar
7 Respuestas
16th Nov 2017, 10:28 PM
Ilia Fedorov
Ilia Fedorov - avatar
+ 3
@Eligijus Silkartas But you did not consider that the sum of these two angles may be greater than 180, then the triangle does not exist.
16th Nov 2017, 10:38 PM
Ilia Fedorov
Ilia Fedorov - avatar
+ 2
double thirdAngle (double first , double second) { if (first < 0 || second < 0) { cout << "Invalid Inputs\n"; return -1; } else if ( first + second >= 180) { cout << "It's not a Triangle !!\n"; return -1; } else { return (180 - first - second); } }
19th Nov 2017, 6:04 AM
Asit Shah
Asit Shah - avatar
+ 1
If this is euclidean geometry, then: def angle3(angle1, angle2): return 180 - angle1 - angle2
16th Nov 2017, 10:30 PM
Eligijus Silkartas
Eligijus Silkartas - avatar
+ 1
@Ilia Fedorov Yes that's true. There are more things to consider, like passed values can be negative or they can even be not numbers. But I am too lazy to write that code :D
16th Nov 2017, 10:44 PM
Eligijus Silkartas
Eligijus Silkartas - avatar
0
is it on python??????????????
17th Nov 2017, 5:02 PM
Tufan Rahman
Tufan Rahman - avatar
18th Nov 2017, 3:17 AM
Mickel
Mickel - avatar