December 2005
Beginner to intermediate
618 pages
20h 19m
English
hypot
Calculates a hypotenuse by the Pythagorean formula
#include <math.h> doublehypot( doublex, doubley); floathypotf( floatx, floaty); long doublehypotl( long doublex, long doubley);
The hypot() functions
compute the square root of the sum of the squares of their
arguments, while avoiding intermediate overflows. If the result
exceeds the function’s return type, a range error may occur.
double x, y, h; // Three sides of a triangle printf( "How many kilometers do you want to go westward? " ); scanf( "%lf", &x ); printf( "And how many southward? " ); scanf( "%lf", &y ); errno = 0; h = hypot( x, y ); if ( errno ) perror( _ _FILE_ _ ); else printf( "Then you'll be %4.2lf km from where you started.\n", h );
If the user answers the prompts with 3.33 and 4.44, the program prints this
output:
Then you'll be 5.55 km from where you started.
Read now
Unlock full access