Si 函数,sin函数使用方法
sin x的近似值按如下公式计算,计算精度为10-10:。#include 为C语言中的库函活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!!1 #include 2 #include 3 using namespace std; 4 const double TINY_VALUE = 1e-10; //计算精度 5 6 double tsin { //为了和标准库中的sin()函数区别,所以取名为tsin()函数 7 double n = x,sum=0; 8 int i = 1; 9 do10 {11 sum += n;12 i++;13 n = -n * x*x / / ;14 15 } while ;16 return sum;17 }18 int main() {19 int r, s;20 double k;21 cin >> r >> s;22 if (r*r
计算如下公式,并输出结果:
?
其中r、s的值由键盘输入。sin x的近似值按如下公式计算,计算精度为10-10:
?
?
程序说明:
#include 和#include的区别:
#include 为C语言中的库函活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!! 点击查看数,由于C++兼容C,所以仍可以使用此函数库
在C++中推荐使用 #include , 两者中的函数以及使用方法几乎完全相同
?
C++代码如下:
1 #include 2 #include 3 using namespace std; 4 const double TINY_VALUE = 1e-10; //计算精度 5 6 double tsin(double x) { //为了和标准库中的sin()函数区别,所以取名为tsin()函数 7 double n = x,sum=0; 8 int i = 1; 9 do10 {11 sum += n;12 i++;13 n = -n * x*x / (2 * i – 1) / (2 * i – 2);14 15 } while (fabs(n)>=TINY_VALUE);16 return sum;17 }18 int main() {19 int r, s;20 double k;21 cin >> r >> s;22 if (r*r