我正在尝试解决此问题,但由于某种原因,它无法读取我的值和输出中的区域。当我运行它时,给我零。
我将不胜感激任何帮助或建议。
这是输出:
Please enter value of your three vertex x1 y1 x2 y2 x3 y3:
1
2
5
6
8
9
with given vertices 0.00, 0.00, 0.00, 0.00, 0.00, and 0.00, the area is 0.00
--------------------------------
Process exited with return value 0
Press any key to continue . . .
到目前为止,这是我在代码上所做的。
谢谢!
#include<stdio.h>
#include<math.h>
int main(){
float arr[6];
int i;
float side1, side2, side3, sidet, area, x1, y1, x2, y2, x3, y3;
x1=arr[0];
y1=arr[1];
x2=arr[2];
y2=arr[3];
x3=arr[4];
y3=arr[5];
printf("Please enter value of your three vertex x1 y1 x2 y2 x3 y3: \n");
for(i=0; i<6; i++){
scanf("%f", &arr[i]);
}
//calculation
side1=pow(((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)), 0.5);
side2=pow(((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2)), 0.5);
side3=pow(((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1)), 0.5);
//calculations
sidet=(side1+side2+side3)*0.5;
area=pow((sidet*(sidet-side1)*(sidet-side2)*(sidet-side3)), 0.5);
printf("with given vertices %0.2f, %0.2f, %0.2f, %0.2f, %0.2f, and %0.2f, the area is %0.2f",x1,y1,x2,y2,x3,y3,area);
return 0;
}
最佳答案
x1=arr[0];
没有建立关系。它在那时进行分配,而不是基于arr[0]
的某些更高值。
在代码的前面移动以下内容:
printf("Please enter value of your three vertex x1 y1 x2 y2 x3 y3: \n");
for(i=0; i<6; i++) {
scanf("%f", &arr[i]);
}
然后分配
x1=arr[0];
y1=arr[1];
x2=arr[2];
y2=arr[3];
x3=arr[4];
y3=arr[5];