-->

Given a calculator that only has the + operator. How would you implement *,-,/.

Posted by Admin on
Multiplication ( * ) operation

We can add the first number, second number of times.
Say i=4, j=5;

//Run a for loop for 5 times(j), add i in each //cycle.
for j->0 to 4
add sum += i;

Subtraction ( - ) operation.

//Brute force approach
Increment the smaller number and keep a count till it reaches the larger number


Divide ( / ) operation.

follow the method given above for * operation, and keep a count every time you add. That count would be the Quotient.

I hope you like the above post . Please comment if you find the above post interesting . 




No comments:

Post a Comment