Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. double multiply (int a){
  7.     double multiply = 1;
  8.     for (int c = 2; c <= a; c += 2){
  9.         double z = c  / (c - 1.) * c / (c + 1);
  10.         multiply = multiply * z;
  11.     }
  12.     return multiply;
  13. }
  14.  
  15. double multiply_r (int a){
  16.     if (a == 0)
  17.         return 1;
  18.     return a  / (a - 1.) * a / (a + 1) * multiply_r(a - 2);
  19. }
  20.  
  21. int main(){
  22.     int a,b;
  23.     do{
  24.         cout << "Enter a multiple of 2 and >= 2, please." << endl;
  25.         cin >> a;
  26.     }
  27.     while (a&1 || a < 2);
  28.     cout << "Enter 0 to count recursively, otherwise it will be counted normally." << endl;
  29.     cin >> b;
  30.     (b == 0) ? (cout << "Answer is '"<< multiply_r(a) << "'"<< endl) : (cout << "Answer is '" << multiply(a) << "'"<< endl);
  31.     cout << "Press any key for end program.";
  32.     getch();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement