add two numbers in swift

To add two numbers in Swift, you can use the addition operator (+). Here is an example code snippet:

main.swift
let num1 = 10
let num2 = 5
let sum = num1 + num2
print(sum) // Output: 15
74 chars
5 lines

In the code above, we have declared two integer variables num1 and num2, assigned them values of 10 and 5 respectively, and then added them using the + operator. The result is stored in a third variable sum. Finally, we print the value of sum which is 15.

gistlibby LogSnag