Consider a simple form of integer division: m / k where we are guaranteed that m>=0 and k>0. This can be computed as follows: The quotient is 0 when k is greater than m. Otherwise, the quotient is one more than (m-k)/k . Write an int method named quotient that accepts two int parameters, m and k, and recursively calculates and returns the integer quotient of m/k. You can count on m>=0 and k>0. Do not use a division operator here!

Consider a simple form of integer division: m / k where we are guaranteed that m>=0 and k>0. This can be computed as follows: The quotient is 0 when k is greater than m. Otherwise, the quotient is one more than (m-k)/k . Write an int method named quotient that accepts two int parameters, m and k, and recursively calculates and returns the integer quotient of m/k. You can count on m>=0 and k>0. Do not use a division operator here!

LANGUAGE: JAVA

CHALLENGE:

Consider a simple form of integer division: m / k where we are guaranteed that m>=0 and k>0. This can be computed as follows:
The quotient is 0 when k is greater than m.
Otherwise, the quotient is one more than (m-k)/k .
Write an int method named quotient that accepts two int parameters, m and k, and recursively calculates and returns the integer quotient of m/k. You can count on m>=0 and k>0. Do not use a division operator here!

SOLUTION:

int quotient(int m, int k) {
   if(k==1) return m;
   if(k>m) return 0;
   return quotient(m-k, k) +1;
}

Add comment