问:编写一个函数来计算两点之间的距离,并用它来开发另一个函数,该函数将计算顶点为 A(x1, y1)、B(x2, y2) 和 C(x3, y3) 的三角形的面积)。使用这些函数开发一个函数,如果点 (x, y) 在三角形 ABC 内,则返回值 1,否则返回值 0。
#include<stdio.h>
#include<math.h>
float distance(float x1, float y1, float x2, float y2)
{
float dis;
dis = sqrt((pow((x1-x2),2))+(pow((y1-y2),2)));
return dis;
}
float area(float x1, float y1, float x2, float y2, float x3, float y3)
{
float aa;
aa = ((x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2))/2);
return aa;
}
int point(float a, float b, float x1, float y1, float x2, float y2, float x3, float y3, float A)
{
float area(float, float, float, float, float, float);
float a1, a2, a3 ;
a1=area(float a, float b, float x2, float y2, float x3, float y3);
a2=area(float x1, float y1, float a, float b, float x3, float y3);
a3=area(float x1, float y1, float x2, float y2, float a, float b);
if(a1 + a2 + a3 == A)
return 1;
else
return 0;
}
int main()
{
float x1, y1, x2, y2, x3, y3, a, b, di, A;
int p;
printf("Enter the first coordinate: ");
scanf("%f %f",&x1,&y1);
printf("Enter the second coordinate: ");
scanf("%f %f",&x2,&y2);
di = distance(x1,y1,x2,y2);
printf("The distance is: %f\n",di);
printf("Enter the third coordinate: ");
scanf("%f %f",&x3,&y3);
A = area(x1,y1,x2,y2,x3,y3);
printf("The area is: %f\n",A);
printf("Enter the coordinate of point: ");
scanf("%f %f",&a,&b);
p = point(a,b,x1,y1,x2,y2,x3,y3,A);
printf("\n%d",p);
return 0;
}[Error that I am getting][1]
您的问题似乎主要出在您的point
功能上。第一行对您没有任何帮助,因此您可以将其注释掉。
这里的主要问题是您对 area 函数的调用。您将数据类型放在调用中的每个参数前面。在我的测试中,这阻止了编译。
更改,您拨打的线路point
,并指定值a1
,a2
以及a3
以下内容:
a1=area(a, b, x2, y2, x3, y3);
a2=area(x1, y1, a, b, x3, y3);
a3=area(x1, y1, x2, y2, a, b);
这样做,它应该编译并运行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句