I’m trying to write a function to calculate sin of a number in radiant without using the built in sin function in cmath library. I’ve tried over 10 fixed , can’t seem to find the error.
Thought I’d get some help here.
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
int factorial(int n) {
if (n == 1)
return 1;
else
return n*factorial(n - 1);
}
double sinuss(double x,int n) {
if (n < 1)
return x;
else
return pow(-1, n)*(pow(x, 2*n + 1) / (factorial(2*n + 1)) + sinuss(x, n - 1));
}
int main()
{
cout << sinuss(1.0471, 5);
system("pause");
return 0;
}
Thank You !!