Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <cmath>
- using namespace std;
- double cosx(double x)
- {
- double n = 1.0;
- double sum = 0.0;
- int i = 1;
- do
- {
- sum += n;
- n *= -1.0 * x * x / ((2 * i - 1) * (2 * i));
- i++;
- } while (fabs(n) > 0.00000000001);
- return sum;
- }
- int main(int argc, char** argv) {
- double x = 1;
- cout << cosx(x) << endl << cos(x) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement