Answer to Question #265551 in C++ for Usama

Question #265551

Write a recursive algorithm to multiply two positive integers m and n using repeated addition. Specify the base case and the recursive case. 


1
Expert's answer
2021-11-20T06:43:03-0500
#include <iostream>
using namespace std;


int RecursiveProduct(int m, int n)
{
  if (0 == n)
    return 0;


  return m + RecursiveProduct(m, n - 1);
}


int main()
{


  int m, n;


  cout << "Input m = ";
  cin >> m;
  cout << "Input n = ";
  cin >> n;


  cout << "Answer = " << RecursiveProduct(m, n) << "\n";


  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS