fork(1) download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. long double ehoch(long double x){
  7. long double erg = -1;
  8. long long counter = 0;
  9. long double epsilon = 1e-16;
  10. long double next = 1;
  11. counter++;
  12. while(epsilon < abs(next) && counter < 100){
  13. erg += next;
  14. next *= x / counter;
  15. counter++;
  16. }
  17. return erg + 1;
  18. }
  19.  
  20. int main() {
  21. for (double x = 0; x < 10; x++)
  22. cout << x << ": " << setprecision(16) << ehoch(x) << " <-> " << exp(x) << endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
0: 1 <-> 1
1: 2.718281828459045 <-> 2.718281828459045
2: 7.38905609893065 <-> 7.38905609893065
3: 20.08553692318767 <-> 20.08553692318767
4: 54.59815003314424 <-> 54.59815003314424
5: 148.4131591025766 <-> 148.4131591025766
6: 403.4287934927351 <-> 403.4287934927351
7: 1096.633158428459 <-> 1096.633158428459
8: 2980.957987041728 <-> 2980.957987041728
9: 8103.083927575384 <-> 8103.083927575384