#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main ()
{
int i;
double V;
double theta;
double V_theta;
double theta_rad;
double theta_array [63];
double v_theta_array [63];
double theta_rad_array [63];
const double PI = 4.0*atan(1.0);
cout << "FOURIER SERIES" << endl;
cout << "Enter value for voltage (V) : ";
cin >> V;
cout << "Claculate the voltage (theta) by the following formula" << endl;
theta = 0;
for (i = 0; i <= 61; i++)
{
theta_rad = theta*(PI/180);
V_theta = V*((1.0/PI) + ((0.5)*(sin(theta_rad))) -((2.0/PI)*(((1.0/3.0)*(cos(2*theta_rad))) + ((1.0/15.0)*(cos(4.0*theta_rad))) +((1.0/35.0)*(cos(6*theta_rad))))));
v_theta_array = V_theta;
theta_array = theta;
theta_rad_array = theta_rad;
theta = theta + (360.0/61.0);
}
for (int j = 0; j < 3;j++)
{
cout << "angle(degrees) angle(radians) voltage(v)\t";
}
cout << "\n";
const int XMAX = 21;
for (int x = 0; x <= XMAX ; x++)
{
cout << theta_array[x]<<"\t\t" << theta_rad_array[x] <<"\t\t" << v_theta_array[x] << "\t\t\t" << theta_array[x+XMAX]<<"\t\t" << theta_rad_array[x+XMAX]<<"\t\t" << v_theta_array[x+XMAX] << "\t\t\t" << theta_array[x+2*XMAX] <<"\t\t" << theta_rad_array[x+2*XMAX] <<"\t\t" << v_theta_array[x+2*XMAX]<<"\n";
}