Question
The Division Algorithm states: If a and b are integers such that b > 0 , then there are unique integers q and r such
The Division Algorithm states: If a and b are integers such that b > 0, then there are unique integers q and r such that a = bq + r with 0 r < b.
q is the quotient, r is the remainder, a is the dividend, and b is the divisor. *Note: the division algorithm is actually a theorem, not an algorithm. There are a few different
ways to compute q and r given the numbers a and b.
Write a Python program that will take as input the integers a and b (where b>0) and then compute the quotient q and remainder r. You are not allowed to use the % or // operators for this one! Also, DONT just compute a/b using integer division for the quotient then set r=a- a/b. You cant use floor function either. Basically, find the quotient and remainder using addition/subtraction.
Suggestion: split the problem into 2 cases. Case 1: a0. Case 2: a<0.
Hint: in Case 1, you could iteratively subtract b from a until the result becomes smaller than a. Case 2 is similar to Case 1, but be careful with the value of the quotient and remainder (remember, remainder has to be positive). Also, make sure your program can handle it when b>a.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started