【发布时间】:2013-06-14 06:19:26
【问题描述】:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main(void)
{
int x,y,g,f,r,X=0,Y=0;
double res=0;
printf("\nEnter the x and y coordinate of the point separated by a space");
scanf("%d %d",&x,&y);
printf("\nEnter the coordinates of the center of the circle ");
scanf("%d %d",&g,&f);
printf("\nEnter the radius of the circle");
scanf("%d",r);
X=x-g;
Y=y-f;
res=(pow((double)X,2.0)+pow((double)Y,2.0)-pow((double)r,2.0));
printf("%lf",res);
if(res>0)
printf("\nThe point lies inside the circle");
else if(!res)
printf("\nThe point lies on the circle ");
else if(res>0)
printf("\nThe point lies outside the circle");
getch();
return 0;
}
上面的代码是一个检查点是否在圆内的程序(我被特别要求使用C的幂函数)。我正在使用 MinGW(截至 2013 年 6 月 14 日的最新版本)来编译我的程序 Windows 7 OS。
程序编译没有任何错误或警告。
但是,当我在命令提示符下运行它时,一旦我输入了所有详细信息,程序就会突然终止。由于下一步是计算res,所以我认为使用幂函数存在错误。请指出相关错误。
【问题讨论】:
-
调试器说什么?
-
离题,但我知道你被特别要求使用 pow 但不要使用
pow((double)X,2.0),因为你可以简单地写(double)X*X(下次)。 -
对不起,我在匆忙中忽略了明显的问题,(ROOKIE HERE)但我想现在无法删除问题
标签: mingw