Write recursive function that multiplies the two integre num

Write recursive function that multiplies the two integre numbers m times n. Besure you include comments in your program (document).

Solution

Times.cpp

#include <iostream>

using namespace std;
int getTimes(int m, int n);
int main()
{
int m,n;
cout << \"Enter m value: \";
cin >> m;
cout << \"Enter m value: \";
cin >> n;
int result = getTimes(m,n);
cout<<\"Result is \"<<result<<endl;

return 0;
}
int getTimes(int m, int n){
if(n == 0){
return 0;
}
else{
return m + getTimes(m,n-1);
}
}

Output:

sh-4.3$ g++ -std=c++11 -o main *.cpp                                                                                                                                                                                             

sh-4.3$ main                                                                                                                                                                                                                     

Enter m value: 2                                                                                                                                                                                                                 

Enter m value: 3                                                                                                                                                                                                                 

Result is 6

Write recursive function that multiplies the two integre numbers m times n. Besure you include comments in your program (document).SolutionTimes.cpp #include &l

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site