泰勒展开式求sin(x)

#include 
#include 

#define TRUE 1
#define FALSE 0
#define BOOL unsigned


double get_result(double x, int n);
double get_n(int n);	// n的阶乘

int main(void)
{


    printf("get_result(0.3, 8) = %lf, ", get_result(0.3, 8));
    printf("get_result(0.5, 20) = %lf, ", get_result(0.5, 20));
    return 0;
}


//
double get_result(double x, int n)
{
    double ret = 0;
    int i = 0;
    for(i = 1; i <= n; i++)
    {
        ret += pow(-1, i-1)*pow(x, 2*i-1)/get_n(2*i-1);
    }

    return ret;
}

double get_n(int n)
{
    int i;
    double n1 = 1;
    for(i=1; i<=n; i++)
        n1 = n1*i;
    return n1;
}

你可能感兴趣的:(C,c++,算法,c语言)