Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Swift Double quotientAndRemainder()
In this tutorial, we will learn about the Swift Double quotientAndRemainder() method with the help of examples.
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.
Did you find this article helpful?