Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int fact(int n) {
  5. if (n == 0) return 1;
  6. return n * fact(n - 1);
  7.  
  8. }
  9. double sum(int n) {
  10. /*int s = 0;
  11. while(n>0){
  12.  
  13. s += (2.0 * n )/ ((2.0 * n - 1) * fact(2.0 * n + 2.0));
  14. n--;
  15.  
  16. }*/
  17. if (n == 1) return (2/(3*fact(4)));
  18. return ((2*n)/(((2 * n) - 1) * fact((2 * n) + 2)))+ sum(n-1);
  19. //return s;
  20. }
  21. int main(){
  22. cout<<fact(3)<<endl;
  23. cout << (double)sum(1)<<endl;
  24. cout << (double)sum(2);
  25.  
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement