如何在 c++ 中以度为单位计算罪恶值
How do I calculate sin values in degree in c++?
我一直在为一个简单的科学计算器编写代码。现在,我已经使用了math.h库,但它给出了sin,cos,tan的值,以弧度为单位,而我想要的是度数。我尝试使用* 180/PI,但它不起作用。另一方面,它与反数值一起工作(*180/PI(。
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Sin = "<<sin(a)*180.0/PI <<endl;
break;
case 8:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Cos = "<<cos(a)*180.0/PI <<endl;
break;
case 9:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Tan = "<<tan(a)*180.0/PI <<endl;
我希望输出以度为单位,但它没有正确显示。同时,这是它正常工作的反向代码。
case 10:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Inverse of Sin = "<<asin(a)*180.0/PI<<endl;
break;
case 11:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Inverse of Cos = "<<acos(a)*180.0/PI<<endl;
break;
case 12:
cout<<"Enter the number : ";
cin>>a;
cout<<endl;
cout<<"Inverse of tan = "<<atan(a)*180.0/PI<<endl;
break;
我希望输出以度为单位
不,你没有。您希望将输入解释为度数。
sin
和cos
不返回角度,因此您不能将它们的返回值称为度或弧度。
在应用sin
或cos
之前,您不仅需要将弧度<->度转换为角度,还需要将度转换为弧度,而不是相反。因此,您需要*PI/180
,而不是*180/PI
。
而不是
cout<<"Sin = "<<sin(a)*180.0/PI <<endl;
你想要
cout<<"Sin = "<<sin(a*PI/180.0) <<endl;
相关文章:
- 以天C++为单位的两个时间戳之间的差异
- 如何以毫秒为单位获取开始时间和 now() 之间的毫秒差异(以 C++为单位?
- 从原始字节解码协议缓冲区(以 C++为单位)
- 如何以C++为单位计算向量中的字节数?
- 如何以字节为单位计算mpz_class的长度?
- 以C++为单位计算数组中的重复数字
- 以 ns3 为单位计算数据包接收时间
- 以 C++ 为单位计算字符串中的唯一单词
- 计算以毫秒为单位的分类算法对整数阵列排序的时间
- 以秒为单位计算年龄的程序无法正常工作
- 如何在 c++ 中以度为单位计算罪恶值
- 如何计算 A、B、C <= 10^18 的 (A*B)%C(以 C++为单位)?
- 如何以毫秒为单位计算执行时间
- 在 openCV 中以像素为单位计算字符串的长度
- 以 C++ 为单位计算有序集的并集
- 当 x 为 90 度或 pi/2 弧度时,将 cos(x) 计算为 0,以C++为单位
- PCL:以毫米为单位计算点的xyz
- 提升:以秒/毫/微米/纳米为单位计算函数的运行时间
- 设计一个结构来存储时间和日期.写一个函数来计算两个时间之间的差(以分钟为单位)
- 逻辑错误:平均质心计算不正确,无限执行,'entries '函数 - K 表示一组点的聚类,以C++为单位