#include <iostream>
#include <vector>
#include <cmath>
#include <fstream>

using namespace std;

//My version of the sine function, computed using the N terms of the
//series solution
double mysin(int N, double x)
{
 //Initialise the answer to zero
 double answer = 0.0;
 //Initialise the first term of the series
 double term = x;
  
 //Loop over the terms of the series
 for(int i=1;i<=N;i++)
  {
   //At the term to the sum
   answer += term;
   //Multiply the term by the appropriate factor
   term *= -x*x/((2*i+1)*2*i);
  }

 //Return the final sum
 return answer;
}

//Main code
int main()
{

 //Open an output file
 ofstream file("output.dat");

 //Initialise the value of our coordinate x
 double x = 0.0;; 

 //Set the output precision to 20 digits
 file.precision(20);
 //Loop over 50 points
 for(unsigned int i=0;i<50;i++)
  {
   //Increase the value of x by 2pi/50
   //Note that pi is calculated using the atangent of 1.0 (= pi/4)
   x += 8.0*atan(1.0)/50.0;
   //Output the value of x, built-in sine function and mysin function
   //using only three terms in the sum
   file << x << " " << sin(x) << " " << mysin(3,x) << endl;
  }
}
