re: Daily Challenge #84 - Third Angle of a Triangle VIEW POST

FULL DISCUSSION
 

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

code of conduct - report abuse