gpt4 book ai didi

c - 使用给定顶点的数组查找三角形的面积以供用户提示

转载 作者:行者123 更新时间:2023-11-30 16:27:28 25 4
gpt4 key购买 nike

我正在尝试解决这个问题,但由于某种原因它没有读取我的值和输出中的区域。当我运行它时,给我零。我将不胜感激任何帮助或建议。

这是输出:

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;
}

最佳答案

这是完整的工作代码:

#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;

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];


//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;
}

关于c - 使用给定顶点的数组查找三角形的面积以供用户提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52713221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com