#include <cstdlib>
#include <iostream>
#include <fstream>
float cos(float x, int n);
float sin(float x, int n);
float fact(int n);
float power(float x, int n);
using namespace std;
int main(int argc, char *argv[])
{
const float pi(22.0/7);
float e, f, g;
int n, x, count=0;
ifstream fin("ang.txt");
fin>>x;
cout<<"How many terms do you want to sum to?"<<endl;
cin>>n;
cout<<endl<<"Angle sin cos tan"<<endl;
cout<<"---------------------------------"<<endl;
while (!fin.eof())
{
count++;
e=sin(x,n)*180/pi;
f=cos(x,n)*180/pi;
g=sin(x,n)/cos(x,n)*180/pi;
cout<<e<<f<<g<<endl;
}
fin.close();
system("PAUSE");
return EXIT_SUCCESS;
}
float fact(int n)
{
if (n<2)
return 1;
else
return n*fact(n-1);
}
float power(float x, int n)
{
if (n==0)
return 1;
else
return x*power(x,n-1);
}
float sin(float x, int n)
{
if (n==0)
return 1;
else
return power(-1,n)*power(x,2*n+1)/fact(2*n+1);
}
float cos(float x, int n)
{
if (n==0)
return 1;
else
return power(-1,n)*power(x,2*n)/fact(2*n);
}
#include <cstdlib>
#include <iostream>
#include <fstream>
float cos(float x, int n);
float sin(float x, int n);
float fact(int n);
float power(float x, int n);
using namespace std;
int main(int argc, char *argv[])
{
const float pi(22.0/7);
float e, f, g;
int n, x, count=0;
ifstream fin("ang.txt");
fin>>x;
cout<<"How many terms do you want to sum to?"<<endl;
cin>>n;
cout<<endl<<"Angle sin cos tan"<<endl;
cout<<"---------------------------------"<<endl;
while (!fin.eof())
{
count++;
e=sin(x,n)*180/pi;
f=cos(x,n)*180/pi;
g=sin(x,n)/cos(x,n)*180/pi;
cout<<e<<f<<g<<endl;
}
fin.close();
system("PAUSE");
return EXIT_SUCCESS;
}
float fact(int n)
{
if (n<2)
return 1;
else
return n*fact(n-1);
}
float power(float x, int n)
{
if (n==0)
return 1;
else
return x*power(x,n-1);
}
float sin(float x, int n)
{
if (n==0)
return 1;
else
return power(-1,n)*power(x,2*n+1)/fact(2*n+1);
}
float cos(float x, int n)
{
if (n==0)
return 1;
else
return power(-1,n)*power(x,2*n)/fact(2*n);
}
#include <cstdlib>
#include <iostream>
#include <fstream>
float cos(float x, int n);
float sin(float x, int n);
float fact(int n);
float power(float x, int n);
using namespace std;
int main(int argc, char *argv[])
{
const float pi(22.0/7);
float e, f, x;
int n, a;
ifstream fin("ang.txt");
fin>>a;
cout<<"How many terms do you want to sum to?"<<endl;
cin>>n;
e=sin(x,n)*180/pi;
f=cos(x,n)*180/pi;
cout<<endl<<"angle "<<a<<": sin = "<<e<<" cos = "<<f<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
float fact(int n)
{
if (n<2)
return 1;
else
return n*fact(n-1);
}
float power(float x, int n)
{
ifstream fin("ang.txt");
fin>>x;
if (n==0)
return 1;
else
fin.close();
return x*power(x,n-1);
}
float sin(float x, int n)
{
ifstream fin("ang.txt");
fin>>x;
do
{
if (n==0)
return 1;
else
fin.close();
return (power(-1,n)*power(x,(2*n)+1))/fact((2*n)+1);
} while(!fin.eof());
}
float cos(float x, int n)
{
ifstream fin("ang.txt");
fin>>x;
if (n==0)
return 1;
else
fin.close();
return (power(-1,n)*power(x,2*n))/fact(2*n);
}
float sin(float x, int n)
{
ifstream fin("ang.txt");
fin>>x;
do
{
if (n==0)
return 1;
else
fin.close();
return (power(-1,n)*power(x,(2*n)+1))/fact((2*n)+1);
} while(!fin.eof());
int main(int argc, char *argv[])
{
const double pi(22.0/7);
int e, f, x, n;
ifstream fin("ang.txt");
fin>>x;
cout<<"How many terms do you want to sum to?"<<endl;
cin>>n;
e=sin(x,n)*180/pi;
f=cos(x,n)*180/pi;
cout<<endl<<"angle "<<x<<": sin = "<<e<<" cos = "<<f<<endl;
system("PAUSE");
return EXIT_SUCCESS;
fin.close();
}
double sin(double x, int n)
{
if (n==0)
return 1;
else
return (power(-1,n)*power(x,(2*n)+1))/fact((2*n)+1);
}
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
//initializing all of the functions
double cos(double x, int n);
double sin(double x, int n);
double fact(int n);
double power(double x, int n);
using namespace std;
int main(int argc, char *argv[])
{
//initializing the variables
const double pi(22.0/7);
double e, f, g, n, x, count=0;
//opening the input file and getting how many times it should be summed together
ifstream fin("ang.txt");
cout<<"How many terms do you want to sum to?"<<endl;
cin>>n;
cout<<endl<<"Angle sin cos tan"<<endl;
cout<<"---------------------------------"<<endl;
// while loop that calls the functions, converts to radians, and prints out the results
while (!fin.eof())
{
count++;
fin>>x;
e=sin(x*pi/180.0,n);
f=cos(x*pi/180.0,n);
g=e/f;
cout<<fixed<<setprecision(3)<<x<<" "<<e<<" "<<f<<" "<<g<<endl;
}
fin.close();
system("PAUSE");
return EXIT_SUCCESS;
}
//this recursive function calculates the factorial part
double fact(int n)
{
if (n<2)
return 1;
else
return n*fact(n-1);
}
//this function calculates the power part
double power(double x, int n)
{
if (n==0)
return 1;
else
return x*power(x,n-1);
}
//this function calculates sin
double sin(double x, int n)
{
if (n==0)
return x;
else
return power(-1,n)*power(x,2*n+1)/fact(2*n+1)+sin(x,n-1);
}
//this function calculates cos
double cos(double x, int n)
{
if (n==0)
return 1;
else
return power(-1,n)*power(x,2*n)/fact(2*n)+cos(x,n-1);
}
xscurry said:Now try doing it in assembly without the nice libraries and functions of C++.![]()