Skip to content

Commit

Permalink
Bai_3_calculcus
Browse files Browse the repository at this point in the history
  • Loading branch information
bacbahieu committed Mar 14, 2024
1 parent 6d67a84 commit 78506e3
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions AdvProg_L2-Calculus/calculus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#include <string>
#include <cmath>

using std::string;
using std::cout;
using std::endl;
using std::stod;

using std::string;

double mySin(double x);
double myCos(double x);
Expand All @@ -18,9 +17,10 @@ double mySqrt(double x);
Returns:
double: cosine of x
***/
double myCos(double x)
double myCos(double x)
{
return 0.0;
double ket_qua = 1 - pow(x, 2) / 2 + pow(x, 4) / 24 - pow(x, 6) / 720;
return ket_qua;
}

/***
Expand All @@ -31,22 +31,30 @@ double myCos(double x)
***/
double mySin(double x)
{
return 0.0;
double ket_qua = x - pow(x, 3) / 6 + pow(x, 5) / 120 - pow(x, 7) / 5040;
return ket_qua;
}


/***
Args:
x (double): a number
Returns:
double: square root of x
***/
double mySqrt(double x) {
if (x < 0) {
double mySqrt(double x)
{
if (x < 0)
{
cout << "Invalid argument" << endl;
exit(1);
}


return 0;
else
{
double ket_qua = x;
for (int i = 0; i < 5; i++)
{
ket_qua = (ket_qua + x / ket_qua) / 2;
}
return ket_qua;
}
}

0 comments on commit 78506e3

Please sign in to comment.