How to calculate the area of a pentagon in Swift

2 Answers

0 votes
import Foundation

func pentagonArea(side: Double, apothem: Double) -> Double {
    5.0 * (side * apothem) / 2.0
}

let side = 5.0
let apothem = 3.0

let area = pentagonArea(side: side, apothem: apothem)

print(String(format: "Area = %.2f", area))


/*
run:

Area = 37.50

*/

 



answered 3 hours ago by avibootz
0 votes
import Foundation

func area_regular_pentagon(_ side: Double) -> Double {
    return (1.0 / 4.0) * sqrt(5 * (5 + 2 * sqrt(5))) * pow(side, 2)
}

print(area_regular_pentagon(7))


/*
run:

84.30339262885938

*/

 



answered 1 hour ago by avibootz
...