没有cmath库的余弦计算
Cosine Calculation without cmath library
我是一名计算机科学专业的学生。我被分配了一个项目,我需要使用C++创建一个小程序,该程序将询问度数或弧度,然后输出sin、cos和tan值,但我只能使用#include <iostream>
。正弦值工作正常,但余弦值是个问题。这是我用来计算的代码:
float rad = radian value;
float func_cos (float rad)
{
float cos;
int i = 0;
float sum = 0;
float x = rad;
while (fabs(x) > 0.000001)
{
i = i + 2;
x = -(x) * ((rad*rad)/(i*(i-1)));
sum = (sum) + (x);
}
cos = 1 - sum;
return cos;
}
您有sin(x)
工作吗?那就很容易了。cos(x) = sin(x + pi/2)
我同意"Oli Charlesworth","fabs(x)"函数不在"iostream"标头中。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 递归函数计算序列中的平方和(并输出过程)
- (C++)分析树以计算返回错误值的简单算术表达式
- 我的字符计数代码计算错误.为什么
- 在计算中使用二的幂有多有利可图
- 如何计算文件中的"columns"数?
- 计算排序向量的向量中唯一值的计数
- 如何使用 std::累积在 C++ 中计算总和立方体
- 使用Qt C++计算类似Git的SHA1哈希
- OpenCV C++.快速计算混淆矩阵
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- C++如何计算用户输入的数字中的偶数位数
- 如何计算数据类型的范围,例如int
- 类似枚举的计算常量
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 在矢量中使用值(特征)来计算OpenCV的余弦相似性
- 没有cmath库的余弦计算
- 余弦没有计算出确切的值
- 计算余弦在c++与泰勒级数和近似输入