Advertisement
JewishCat

1.8

Jan 14th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <cmath>
  5. using namespace std;
  6. #define PRECISION 1e-4
  7. double _exp(const double x)
  8. {
  9.     double dVal, dTemp;
  10.     int nStep = 1;
  11.     for (dVal = 1.0, dTemp = 1.0; fabs(dTemp) >= PRECISION; ++nStep)
  12.     {
  13.         dTemp *= x / nStep;
  14.         dVal += dTemp;
  15.     }
  16.     return dVal;
  17. }
  18.  
  19.  
  20. int main(int argc, char** argv) {
  21.  
  22.     double x = -1;
  23.     cout << _exp(x) << endl << exp(x) << endl;
  24.     system("pause");
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement