How to calculate the area of a pentagon in Kotlin

2 Answers

0 votes
fun pentagonArea(side: Double, apothem: Double): Double =
    5.0 * (side * apothem) / 2.0

fun main() {
    val side = 5.0
    val apothem = 3.0

    val area = pentagonArea(side, apothem)

    println("Area = %.2f".format(area))
}


/*
run:

Area = 37.50

*/

 



answered 2 hours ago by avibootz
0 votes
import kotlin.math.sqrt
import kotlin.math.pow

fun area_regular_pentagon(side: Double): Double {
    return (1.0 / 4.0) * sqrt(5 * (5 + 2 * sqrt(5.0))) * side.pow(2.0)
}

fun main() {
    println(area_regular_pentagon(7.0))
}


/*
run:

84.30339262885938

*/

 



answered 1 hour ago by avibootz
...