To divide two numbers in Swift, you can use the division operator /
. Here's an example:
main.swift51 chars3 lines
In the above example, we're dividing the number 10
by 2
, which results in the quotient 5
. Note that the result of this operation is automatically inferred by Swift to be of type Int
.
If you want to perform division on two floating-point numbers, you can use the same division operator /
. Here's an example:
main.swift72 chars3 lines
In the above example, we're dividing the number 10.0
by 3.0
, which results in the quotient 3.3333333333333335
. Note that the result of this operation is automatically inferred by Swift to be of type Double
.
gistlibby LogSnag