c - Why does the `sqrt()` print the desired output when I use `float`s instead of `double`s? -
#include <stdio.h> #include <math.h> double hypotenuse( double side1, double side2 ); int main( void ) { double a, b; printf( "enter values of 2 sides: " ); scanf( "%f %f", &a, &b ); printf( "\nthe length of hypotenuse is: %f", hypotenuse( a, b ) ); getchar(); getchar(); return 0; } double hypotenuse( double side1, double side2 ) { double c; c = (side1 * side1) + (side2 * side2); return sqrt( c ); }
the above program works when use float a, b;
instead of double a,b;
. why?
in code, use
scanf( "%f %f", &a, &b );
but %f
used float
,not double
. try %lf
double
.
Comments
Post a Comment