C 从3个坐标点找到三角形的面积,返回0

C 从3个坐标点找到三角形的面积,返回0,c,debugging,math,area,C,Debugging,Math,Area,所以我的程序在这里假设取3个值,并将其存储在变量Ax,Ay等中。。。但出于某种原因,它一直在为面积返回0.00,从我看到的所有代码都应该返回一个适当的面积,它对面积应用了距离公式和heron公式 #include <stdio.h> #include <math.h> int main(void) { float Ax,Ay,Bx,By,Cx,Cy,A,B,C,side,area; printf("hello inPut x,y coords");

所以我的程序在这里假设取3个值,并将其存储在变量Ax,Ay等中。。。但出于某种原因,它一直在为面积返回0.00,从我看到的所有代码都应该返回一个适当的面积,它对面积应用了距离公式和heron公式

#include <stdio.h>
#include <math.h>

int main(void) {
    float Ax,Ay,Bx,By,Cx,Cy,A,B,C,side,area;
    printf("hello inPut x,y coords");
    printf("input 3 numbers for your x coordinates");
    scanf("%f%f%f",&Ax,&Bx,&Cx );
    printf("input 3 numbers for your y coordinates");
    scanf("%f%f%f",&Ay,&By,&Cy);

    A=sqrt(((Bx-Ax)*(Bx-Ax))+((By-Ay)*(By-Ay)));
    B=sqrt(((Cx-Bx)*(Cx-Bx))+((Cy-By)*(Cy-By)));
    C=sqrt(((Ax-Cx)*(Ax-Cx))+((Ay-Cy)*(Ay-Cy)));



    side=((A+B+C)/2);

    area=sqrt(side*(side-A)*(side-B)*(side-C));
    printf("n AREA OF TRIANGLE IS %f",area);

}

您的代码运行良好。我用Triples 1.2.8 7.8和1.3 2.3 0.1进行了尝试,这很好。也许你用,而不是。对于十进制分隔…

请编辑您的问题,并指定您的输入和预期输出。您检查了输入值吗?您用于计算的值是什么?由于返回类型为int,我希望这里会出现舍入或trunctaion问题,特别是当面积小于1时。@buffo:您的输入1,4 2,5,3,6定义了一个零面积三角形,其中所有三条边都是平行的,所以这不是一个好例子。@buffo:嗯,这是一个典型的情况,现在可以当场组成六个数字,我会说::-FWIW,我检查的几个输入也有很好的答案。也许你可以扩展你的答案,包括为什么。分隔符在这里吗,。这也可能给他一些见解。
Take 3 numbers like 
5,7,8
These first three numbers are now stored in Ax,Bx,Cx (Ax=5,Bx=7,Cx=8)
Take 3 more numberss for the y coordinate (1,2,3)
Store numbers in Ay By Cy (Ay =1, By=2, Cy=3)

take these values and calculate the distance between them by using this formula:

sqrt((Bx-Ax)^2+(By-Ay)^2)
repeat this 2 more time for the other numbers

now it calculates the perimeter of the triangle, and halves it , then inputs it into the heron formula to get the area.

Ideally these values should give an area > 0.