### Alternative to if else?

SOi wrote this code for the recursive method and I really wanted to know if I can do this problem without using if else. what would be the appropriate replacement for if else statement?
Thanks!
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051`` `````` #include #include; using namespace std; int re(int n); float b(int n); int main() { int a; cout << "Please entet a positive number\n"; cin >> a; cout << re(a) << endl;; cout << b(a) << endl; system("pause"); return 0; } float b(int n) { if (n == 1) { return 2; } else { return pow((-1.0), n)*sqrt(n)*b(n - 1); } } int re(int n){ if (n == 1) { return 3; } else if (n == 0) { return -2; } else { return 2 *re(n - 1) + 3* re(n - 2); } }``````
Last edited on
 ``1234567`` ``````#include double b( int n ) // invariant: positive n { return n == 1 ? 2 : std::pow( -1.0, n ) * std::sqrt(n) * b(n-1) ; } int re( int n ) // invariant: non-negative n { return n == 1 ? 3 : ( n == 0 ? -2 : 2 * re(n-1) + 3 * re(n-2) ) ; }``````
Thank you very much!
Topic archived. No new replies allowed.