The quotientAndRemainder()
method calculates the quotient and remainder of the division of numerator by denominator.
Example
// compute the quotientAndRemainder
var result = 10.quotientAndRemainder(dividingBy: 3)
print(result)
// Output: (quotient: 3, remainder: 1)
quotientAndRemainder() Syntax
The syntax of the quotientAndRemainder()
method is:
num.quotientAndRemainder(dividingBy: otherNumber)
Here, num
is a numerator.
quotientAndRemainder() Parameters
The quotientAndRemainder()
method takes one parameter
otherNumber
- the dividing value (denominator)
quotientAndRemainder() Return Values
The quotientAndRemainder()
method returns the quotient and remainder of the division of num
by otherNumber
.
Example: Swift Double quotientAndRemainder()
// compute quotient and remainder
var result1 = 150.quotientAndRemainder(dividingBy: 2)
print(result1)
var result2 = 1750.quotientAndRemainder(dividingBy: 9)
print(result2)
Output
(quotient: 75, remainder: 0) (quotient: 194, remainder: 4)
Here, we have used the quotientAndRemainder()
method to compute the quotient and remainder while the numerator is divided by the denominator.