c++(函数,余弦)没有给出正确答案
C++ ( function, cosine) not giving the correct answer
我一个月前才开始学这门c++课程。现在我要写一个程序来计算这个。我不知道我做错了什么。
#include <stdio.h>
#include <math.h>
float gatherl1();
float gatherl2();
float gatheran();
void values(float,float,float);
float findlength(float,float,float);
float findan2(float,float,float);
float findan3(float,float,float);
void name(float,float,float);
int main(void)
{
float length1,length2;
float length3;
float angle1,angle2,angle3;
length1 = gatherl1();
length2 = gatherl2();
angle1 = gatheran();
values(length1,length2,angle1);
length3 = findlength(length1,length2,angle1);
angle2 = findan2(length1,length2,length3);
angle3 = findan3(length1,length2,length3);
name(angle1,angle2,angle3);
}
float gatherl1()
{
float l1;
printf("Enter the length of one of the sides of any trianglen");
scanf("%f",&l1);
return l1;
}
float gatherl2()
{
float l2;
printf("Enter the length of the other siden");
scanf("%f",&l2);
return l2;
}
float gatheran()
{
float angle;
printf("Enter the angle between them.n");
scanf("%f",&angle);
return angle;
}
void values(float l1, float l2, float angle)
{
printf("n The two sides are %f and %f. The angle between them is %f n",l1,l2,angle);
}
float findlength(float l1, float l2, float angle)
{
float l3,pyt,boy;
if (angle==90)
{
pyt = pow(l1,2) + pow(l2,2);
l3 = sqrt(pyt);
}
else
{
boy = pow(l1,2) + pow(l2,2) - 2*l1*l2*cos(angle);
l3 = sqrt(boy);
}
printf("nthe third side is = %f",l3);
return l3;
}
float findan2(float l1, float l2, float l3)
{
float cosangle2,angle2;
cosangle2 = (pow(l2,2) + pow(l3,2) - pow(l1,2)) / (2*l2*l3);
angle2 = acos(cosangle2);
return angle2;
}
float findan3(float l1, float l2, float l3)
{
float cosangle3,angle3;
cosangle3 = (pow(l1,2) + pow(l3,2) - pow(l2,2)) / (2*l1*l3);
angle3 = acos(cosangle3);
return angle3;
}
void name(angle,angle2,angle3)
{
printf("nnn the other two angles are %f and %f",angle2,angle3);
printf("nnn The angle you put is %f",angle);
if(angle == 90)
{
printf("n The triangle is a right trianglen");
}
else if(angle < 90)
{
printf("n The triangle is a acute trianglen");
}
else
{
printf("n The triangle is a obtuse trianglen");
}
}
我以前从未使用过cos和arccos函数,所以我不确定这是否是原因。或者是函数,因为我对函数也不熟悉。请救救我!!谢谢你。
传递给函数的值是否以弧度为单位?因为cos和arccos以弧度作为输入
C三角函数的单位是弧度,而不是度数。您必须乘以pi/180
才能将度转换为弧度。
相关文章:
- C++ 中 pow() 函数的输出没有给出准确的答案
- 函数从指针 c++ 中获取错误的值并返回错误的答案
- c++:运行一个函数 8 次,并将每个答案添加到数组或 JSON 中
- 阶乘函数只返回C++中输入的答案
- 给定一个整数 N>0,区间 [0, 2^N) 中有多少个整数正好有 N-1 个设置位?编写一个返回正确答案的简短函数
- 为什么在C++算术函数中加".0"会给出小数点的答案?
- 在 c++ 中将模板与类一起使用时,类成员函数的答案错误?
- 无法在 for 循环中的 pow 函数上输出答案
- 为什么我的函数返回一个整数,尽管我已经将答案指定为浮点数
- 使用幂函数的计算给出了大数字的错误答案
- 试图弄清楚如何使用递归来获得与另一个函数相同的答案
- void 函数使用相同的变量打印两个不同的答案
- ABS 函数在 C++ 中没有给出正确的答案
- 布尔函数的错误答案
- 布尔函数没有给出正确答案
- 无法计算如何从联机答案中返回c++函数的多个值
- 函数的答案不正确
- 无法从非常简单的函数中获得正确答案
- C++构造函数并使其显示默认答案
- 二项式系数函数C++错误答案 n>13