find the area of a circle in swift

To find the area of a circle in Swift, we can follow the formula:

main.swift
Area = pi * radius^2
21 chars
2 lines

Here's the Swift code to calculate the area of a circle:

main.swift
let radius = 5.0
let pi = 3.14

let area = pi * pow(radius, 2)

print("The area of the circle is \(area)") // Output: The area of the circle is 78.5
149 chars
7 lines

In this code, we first define the radius and pi values. Then, we calculate the area using the pi value and the pow function to raise the radius to the power of 2. Finally, we print the result.

related categories

gistlibby LogSnag