Loading...
Select Version
&pagelevel(4)&pagelevel
Definition | #include <math.h> double hypot(double x, double y); These functions calculate the euclidean distance of the point with the coordinates (x,y). | |
Return val. | sqrt(x*x + y*y) | square root of the sum of the squared coordinates. |
| depending on the function type,in the event of an overflow. In addition, | |
Example | #include <stdio.h> #include <math.h> #include <stdlib.h> int main(void) { double x, y, alpha, r, pi; printf("Enter x and y coordinates:\n"); scanf("%lf %lf", &x, &y); pi = 2.0 * asin(1.0); if(x > 0.0) alpha = atan(y/x); else if (x < 0.0) if (y >= 0.0) alpha = atan(y/x) + pi; else alpha = atan(y/x) - pi; else if (y > 0) alpha = pi/2.0; else if (y < 0) alpha = -pi/2.0; else { printf("Angle not defined!\n"); exit(1); } r = hypot(x, y); alpha = alpha * (180.0/pi); printf("The polar coordinates are:\n"); printf("Distance from zero: %g\n",r); printf("Angle to the x axis:\n"); printf("%g degrees\n",((y < 0.0)? alpha + 360 : alpha) ); return 0; } | |
See also | cabs, sqrt |