Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- double multiply (int a){
- double multiply = 1;
- for (int c = 2; c <= a; c += 2){
- double z = c / (c - 1.) * c / (c + 1);
- multiply = multiply * z;
- }
- return multiply;
- }
- double multiply_r (int a){
- if (a == 0)
- return 1;
- return a / (a - 1.) * a / (a + 1) * multiply_r(a - 2);
- }
- int main(){
- int a,b;
- do{
- cout << "Enter a multiple of 2 and >= 2, please." << endl;
- cin >> a;
- }
- while (a&1 || a < 2);
- cout << "Enter 0 to count recursively, otherwise it will be counted normally." << endl;
- cin >> b;
- (b == 0) ? (cout << "Answer is '"<< multiply_r(a) << "'"<< endl) : (cout << "Answer is '" << multiply(a) << "'"<< endl);
- cout << "Press any key for end program.";
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement