写了个三角形三边求面积的程序,不知道错在哪里,总是编译不过去
本帖最后由 bin554385863 于 2019-5-5 04:36 编辑如题
//输入三条三角形边长,计算它的面积
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,x,y,Area;
scanf("%f%f%f",a,b,c);
if (a<=0||b<=0||c<=0)
{
printf("Is the side length of your triangle negative?");
}
else if ((a+b>c)&&(a+c>b)&&(b+c>a))
{
x=(a*a+b*b-c*c)/(2*a*b);
y=sqrt(1-x*x);
Area=(a*b*y)/2;
}
printf("The area of a triangle is:%f",Area);
}
else
{
printf("Is the side length can draw a triangle?")
}
调试结果
Thread 1 hit Breakpoint 1, main () at e:\Administrator\Documents\Visual Studio 2019\Exercises\Triangle.c:7
7 scanf("%f%f%f",a,b,c);
Thread
1 received signal SIGSEGV, Segmentation fault.
0x00007ffc15496f48 in msvcrt!clock () from C:\WINDOWS\System32\msvcrt.dll
到底哪里出错了{:9_220:}
scanf("%f%f%f",a,b,c); 人造人 发表于 2019-5-3 19:56
{:9_220:}又忘了& 我vs提示用scanf_s,楼主怎么没有,教教我呗
页:
[1]