一道简单的老题-四个圆塔
有4个圆塔,圆心坐标分别为(2,2) (-2,2) (-2,-2) (2,-2),圆半径为1,这4个塔的高度为10m,塔以外无建筑物。今输入任意一点的坐标,求该店的建筑高度(塔以外的高度为零)
解答如下:
#include<stdio.h>
#include<math.h>
main()
{float x,y,d;
int h;
scanf("%f,%f",&x,&y);
if(x>0&&y>0)d=sqrt((x-2)*(x-2)+(y-2)*(y-2));
else if(x>0&&y<0)d=sqrt((x-2)*(x-2)+(y+2)*(y+2));
else if(x<0&&y>0)d=sqrt((x+2)*(x+2)+(y-2)*(y-2));
else if(x<0&&y<0)d=sqrt((x+2)*(x+2)+(y+2)*(y+2));
else h=908; /*这里只是测试是否包括(0,0)坐标*/
if(d>1.000001)h=0;
else h=10;
printf("%f,%f\n",x,y);
printf("height=%d",h);
getch();
}
结果输入0,0,高度不是908,这是怎么回事?thx