Program to Find Product of Two Numbers using Recursion in C++.
Solution
#include <iostream> using namespace std; int product(int a, int b) { if (a < b) return product(b, a); else if (b != 0) return (a + product(a, b - 1)); else return 0; } int main() { int a,b,ans; cout<<"Enter two numbers "; cin>>a>>b; ans=product(a,b); cout<<"Answer is "<<ans; return 0; }
Output :
Enter two numbers 5 7 Answer is 35