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 = 0.0000000001;
  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(11) << 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.7182818284 <-> 2.7182818285
2: 7.3890560989 <-> 7.3890560989
3: 20.085536923 <-> 20.085536923
4: 54.598150033 <-> 54.598150033
5: 148.4131591 <-> 148.4131591
6: 403.42879349 <-> 403.42879349
7: 1096.6331584 <-> 1096.6331584
8: 2980.957987 <-> 2980.957987
9: 8103.0839276 <-> 8103.0839276