The following is the algorithm for multiplying two integers
The following is the algorithm for multiplying two integers m and n \"agave la Ruse\" get m, n set product to 0 repeat until m
Solution
#include<iostream>
using namespace std;
int main()
{
//Initializes the m, n and product to given values
int m = 49, n = 5, product = 0;
//Repeat while m is greater than or equals to 1
while(m >= 1)
{
//Display each variable value
cout<<\"\ M = \"<<m<<\"\\t N = \"<<n<<\"\\t Product = \"<<product;
//Check if m is odd
if(m % 2 != 0)
{
//Set the product to product + n
product = product + n;
}
//Set the m to m divided by 2
m = m / 2;
//Set the n to n + n
n = n + n;
}
cout<<\"\ Finally Product = \"<<product;
}
Output
M = 49 N = 5 Product = 0
M = 24 N = 10 Product = 5
M = 12 N = 20 Product = 5
M = 6 N = 40 Product = 5
M = 3 N = 80 Product = 5
M = 1 N = 160 Product = 85
Finally Product = 245
