How can I write my cmath library using functions? help me please!I donT know others.
I must not using include<cmath>
for example;
double sin(double x) //sin function
{return x-((x*x*x)/6.)+((x*x*x*x*x)/120.);}
double cos(double y) //cos function
{return 1-((x*x)/2.)+((x*x*x*x)/24.)-((x*x*x*x*x*x)/720.);}
Last edited on
Pick a function. Look at wikipedia for how to calculate it. Write code to do that.
I will add
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <iostream>
using namespace std;
double sin(double x) //sin function
{return x-((x*x*x)/6.)+((x*x*x*x*x)/120.);}
double cos(double x) //cos function
{return 1-((x*x)/2.)+((x*x*x*x)/24.)-((x*x*x*x*x*x)/720.);}
double tan(double x) //tan function
{return x+(x*x*x/3.)+(2.*x*x*x*x*x/15.)+(17.*x*x*x*x*x*x*x/315.)+(62.*x*x*x*x*x*x*x*x*x/2835.);}
double arcsin(double x) {//arcsin function
if(x<-1 || x>1) {cout<<"not using this function ==>"; }
else {
x=x+(x*x*x/6.)+(3.*x*x*x*x*x/40.)+(5*x*x*x*x*x*x*x/112.)+(35*x*x*x*x*x*x*x*x*x/1152.);}
return x; }
double arccos(double x){//arccos function
if(x<-1 || x>1) {cout<<"not using this function ==>"; }
else {
x=0.5*3.14159-x-(x*x*x/6.)-(3.*x*x*x*x*x/40.)-(5.*x*x*x*x*x*x*x/112.);
return x;}}
double arctan(double x){//arctan function
if(x<-1 || x>1) {cout<<"not using this function ==>"; }
else {
x= x-(x*x*x/3.)+(x*x*x*x*x/5.)-(x*x*x*x*x*x*x/7.);}
return x;}
double exp(double x) //exp function but 12!
{return 1+x+(x*x/2.)+(x*x*x/6.)+(x*x*x*x/24.)+(x*x*x*x*x/120.)+(x*x*x*x*x*x/720.)+(x*x*x*x*x*x*x/5040.)
+(x*x*x*x*x*x*x*x/40320.)+(x*x*x*x*x*x*x*x*x/362880.)+(x*x*x*x*x*x*x*x*x*x/3628800.)+(x*x*x*x*x*x*x*x*x*x*x/39916800.)
+(x*x*x*x*x*x*x*x*x*x*x*x/479001600.); }
double fabs(double x){
if(x<0) {x=x*-1;}
else x=x;
return x;}
int main () {
double a,h;
cin>>a;
cout<<"sin("<<a<<")="<<sin(a*(3.14159/180.))<<endl;
cout<<"cos("<<a<<")="<<cos(a*(3.14159/180.))<<endl;
cout<<"tan("<<a<<")="<<tan(a*(3.14159/180.))<<endl;
cout<<"arcsin("<<a<<")="<<arcsin(a)*(180./3.141)<<endl;
cout<<"arccos("<<a<<")="<<arccos(a)*(180./3.141)<<endl;
cout<<"arctan("<<a<<")="<<arctan(a)*(180./3.141)<<endl;
cout<<"exp("<<a<<")="<<exp(a)<<endl;
cout<<"fabs("<<a<<")="<<fabs(a)<<endl;
system("color c7");
system("pause");
}
|
Last edited on
In your fabs functions, what's
else x=x*1;
for? Seems a bit pointless.
help me please I made all function but I didn'T make log(x) and ln(x) how can I write???