C++ 用函数 泰勒公式求 sinx 的 cosx 值

#include"iostream"
#include "Cmath"// 对比结果,调用库函数;
using namespace std;
double mysin(double);// 声明
double mycos(double);
double myabs(double);     //要求精度的绝对值;


const int pi = 3.1415926;


int main()

{
	cout << " 库函数   的sin(3.14/2)的值为:" << sin(pi / 2) << endl;
	cout << "自定义的  sin(3.14/2)的值为:" << mysin(pi / 2);

	cout << "自定义的sin(56')的值为" << mysin((56.0/180)*pi)<< endl;
	cout << "库函数的 sin(56')的值为" << sin((56.0 / 180)*pi) << endl;


	cout << "库函数的    cos(87)" < 1e-5);
	return sum;


}
double mycos(double x)
{
	double sum = 1,x_pow = 1, item;
	int n = 0, fact = 1, sign = -1;


	fact = fact*(n + 1)*(n + 2);
	item = x_pow / fact*sign;
	x_pow *= x*x; fact;
	sum += item;
	sign = -sign; //    确定要累加这一项的符号;
	
	n += 2;

	return sum;
}
double myabs(double x)
{
	return ((x >= 0 ? x : -x));
}


你可能感兴趣的:(C++ 面向过程学习)