Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
637 B
1
Indexable
//Calcular la siguiente serie
//Ejercicio11y12
#include <iostream>
#include <math.h>
using namespace std;

int factorial(int n)
{
    int a = 1;
    for (int i = 0; i < n; i++)
    {
        a = a * (i + 1);
    }

    return a;
}

double seno(int n, double x)
{
    double suma = 0;
    for (int i = 0; i < n; i++)
    {
        suma += pow(x, 2 * i + 1) / factorial(2 * i + 1) * pow(-1, i);
    }

    return suma;
}

double coseno(int n, double x)
{
    return seno(n, M_PI / 2 - x);
}

int main()
{

    cout << "val: " << coseno(7, 0.5) << endl;
    cout << "val: " << coseno(7, 1) << endl;
}