shrt = r - sqrt(pow(x * 1.0, 2.0) + pow(y * 1.0, 2.0));
I used this code to get the result for shrt = r - square root(x2+y2). But I got the answer wrong. What's wrong with my code? When I print shrt
, the answer is incorrect! Here is my code:
#include <stdio.h>
#include <math.h>
int main() {
int i, x, y, r;
double shrt, lng;
for (i = 0; i < 100; i++) {
scanf("%d %d %d", &x, &y, &r);
shrt = r - sqrt(pow(x * 1.0, 2.0) + pow(y * 1.0, 2.0));
lng = 2 * r - shrt;
printf("%.02lf %.02lf\n", shrt, lng);
}
return 0;
}
If I run the code and input here as a first test case: 0 0 100
. Then I got the output -3.00 -3.00
. But I want the output 100.00 100.00
.