算法提高 7-2求arccos值

版权声明:菜鸟一枚~~ 有想法可在下面评论, 转载标明出处即可。 https://blog.csdn.net/KLFTESPACE/article/details/82778150

问题描述

  利用标准库中的cos(x)和fabs(x)函数实现arccos(x)函数,x取值范围是[-1, 1],返回值为[0, PI]。要求结果准确到小数点后5位。(PI = 3.1415926)
  提示:要达到这种程度的精度需要使用double类型。

样例输入

0.5

样例输出

数据规模和约定

  -1 <= x <= 1, 0 <= arccos(x) <= PI。

#include<iostream>
#include<math.h>
#include<cstdlib>
#include<iomanip>
using namespace std;

int main()
{
double x;
cin>>x;

cout<<fixed<<setprecision(5)<<acos(x);

return 0;
 } 

猜你喜欢

转载自blog.csdn.net/KLFTESPACE/article/details/82778150
今日推荐