find the surface area of a pyramid in go

To find the surface area of a pyramid in go, you need to first calculate the area of each face and then add them together. Here's an example code block that demonstrates how to find the surface area of a pyramid:

main.go
package main

import (
    "fmt"
    "math"
)

func main() {
    // pyramid dimensions
    baseLength := 5.0
    baseWidth := 7.0
    height := 10.0

    // face dimensions
    baseArea := baseLength * baseWidth
    slantHeight := math.Sqrt(math.Pow(height, 2) + math.Pow(baseWidth/2, 2))
    lateralArea := baseWidth * slantHeight / 2

    // total surface area
    surfaceArea := baseArea + 2*lateralArea
    fmt.Printf("Surface Area: %f", surfaceArea)
}
457 chars
23 lines

In this code, we are calculating the surface area of a pyramid with a rectangular base. We first calculate the area of the base, then we use the height and the base width to find the slant height, which is the height of each triangular face. We then use the slant height and base width to calculate the lateral area of each triangular face. Finally, we add the base area and twice the lateral area to get the total surface area of the pyramid.

gistlibby LogSnag