Example:
Base integer = 3
Initial factor = 2
Number of times to process = 3
Process:
1.) 2 x 3 = 6
2.) 6 x 3 = 18
3.) 18 x 3 = 54
Therefore, the output would above would be 54.
Instructions:
#include <iostream>
using namespace std;
int getResult(int base, int initial, int times)
{
while (times > 0)
{
cout << initial << " x " << base << " = " << initial*base << endl;
if(times==1)
return getResult(base, initial, times - 1);
else
return getResult(base,base*initial,times-1);
}
return initial*base;
}
int main()
{
int base, initial, times;
cout << "Please, enter a base integer: ";
cin >> base;
cout << "Please, enter an initial factor: ";
cin >> initial;
cout << "Please, enter a number of times to proccess: ";
cin >> times;
cout<<"Result is "<<getResult(base, initial, times);
}
Comments
Leave a comment