Habsburg

prvi

Apr 7th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main() {
  6. int N = 0;
  7. do {
  8. cout << "Upisite N :D \n";
  9. cin >> N;
  10. }while(N < 1);
  11.  
  12. if(N == 1) {
  13. cout << 1;
  14. return 0;
  15. } else if (N == 2) {
  16. cout << 2;
  17. return 0;
  18. }
  19.  
  20. double e = 2;
  21. double nesto = 2;
  22.  
  23. for(int i = 0; i < N-2 ; ++i) {
  24. nesto = 1;
  25. for(int j = 1; j <= i+2; ++j)
  26. nesto *= j;
  27. e += (1/nesto);
  28. }
  29.  
  30. cout << setprecision(12) << e;
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment