# Daily Challenge #84 - Third Angle of a Triangle

### dev.to staff twitter logo Oct 7 '19・1 min read

Daily Challenge (159 Part Series)

You are given two angles of a triangle in degrees.

Write a function to return the third angle. Only positive integers will be tested.

Sample Tests:

```thirdAngle(30, 60) thirdAngle(60, 60) thirdAngle(43, 78) thirdAngle(10, 20)```

This challenge comes from user5651159. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!

DISCUSS (15) ANSI C

``````#include <math.h>

double third_angle ( double first_angle , double second_angle ) {
first_angle = fmod( first_angle , 360.0 );  // Get absolute
second_angle = fmod( second_angle , 360.0 );

if ( first_angle + second_angle >= 180 )
return 0.0;  // That's not a triangle! OwO

return ( 180 - first_angle - second_angle );
}

int main ( int argc , char ** argv ) {
if (
( int ) third_angle( 30 , 60 ) == 90 &&
( int ) third_angle( 60 , 60 ) == 60 &&
( int ) third_angle( 43 , 78 ) == 59 &&
( int ) third_angle( 10 , 20 ) == 150 )
return 0;  // It works!

return 101;  // Or not
}

``````

Run with `~\$ gcc -lm <file_name> && ./a.out`

Elm

``````import List exposing (all, sum)
import Maybe exposing (andThen, map)

isAngle : Int -> Bool
isAngle angle =
angle > 0 && angle < 180

maybeAngles : List Int -> Maybe (List Int)
maybeAngles angles =
if all isAngle angles && sum angles < 180 then
Just angles

else
Nothing

third : Int -> Int -> Maybe Int
third first second =
maybeAngles [ first, second ]
|> map (sum >> (-) 180)
``````

Test it online

Here.

In Go!

``````func thirdAngle(a, b int) (int, error) {
if (a + b) >= 180 {
return 0, errors.New("Input angles sum is greater than or equal to 180 degress, this cannot be a triangle")
}
if a == 0 || b == 0 {
return 0, errors.New("Input angle cannot be zero, cannot be a triangle")
}
angle := 360 - a - b // sum of angles must be 360 degress
return angle, nil
}

``````

Go Playground

Classic DEV Post from Jul 2 '19

## Introducing Object.fromEntries

`DEV.join()`

Come for the ideas.
Stay for the community.  