如何在 c++ 中以度为单位计算罪恶值

How do I calculate sin values in degree in c++?

本文关键字:为单位 计算 罪恶 c++      更新时间:2023-10-16

我一直在为一个简单的科学计算器编写代码。现在,我已经使用了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;

我希望输出以度为单位

不,你没有。您希望将输入解释为度数。

sincos不返回角度,因此您不能将它们的返回值称为度或弧度。

在应用sincos之前,您不仅需要将弧度<->度转换为角度,还需要将度转换为弧度,而不是相反。因此,您需要*PI/180,而不是*180/PI

而不是

cout<<"Sin = "<<sin(a)*180.0/PI <<endl;

你想要

cout<<"Sin = "<<sin(a*PI/180.0) <<endl;