USING C++ Given two POSITIVE integers num1 and num2 1. Calculate the product of
ID: 643831 • Letter: U
Question
USING C++
Given two POSITIVE integers num1 and num2 1. Calculate the product of num1 and num2 2. Calculate num 1/num2 (integer division) 3. Calculate num 1%num2 (remainder) IMPORTANT - YOU CANNOT USE * (multiply), % (mod) or / (integer div) in your solutions. PLEASE USE WHILE LOOPS and ADDITION (+) and SUBTRACTION (-) to do the above calculations. Test with num1 = 179 num2 = 12 Example Execution: Please enter first positive integer: 179 Please enter second positive integer: 12 The product of 179 and 12 is 2148. The div of 179 and 12 is 14. The remainder when 179 is div by 12 is 11.Explanation / Answer
#include <iostream>
using namespace std;
int main ()
{
int num1 = 0, num2 = 0, product = 0, div = 0, temp = 0, remainder = 0;
cout << "Please enter first positive integer: " << endl;
cin >> num1;
cout << "Please enter second positive integer: " << endl;
cin >> num2;
for (int i = 1; i <= num2; i++)
{
product = product + num1;
}
cout << "The product of " << num1 << " and " << num2 << " is " << product << endl;
temp = num1;
while (num1 >= num2)
{
num1 = num1 - num2;
remainder = num1;
div++;
}
cout << "The division of " << temp << " and " << num2 << " is " << div << endl;
cout << "The remainder of " << temp << " and " << num2 << " is " << remainder << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.