find the surface area of a triangular prism in go

Here is a code snippet to calculate the surface area of a triangular prism in Go:

main.go
package main

import (
	"fmt"
	"math"
)

func main() {
	a := 4.0 // base length of the triangle
	b := 3.0 // height of the triangle
	c := 5.0 // length of the prism
	s := (a * b) / 2 // area of the triangle
	p := math.Sqrt(math.Pow(a/2, 2) + math.Pow(b, 2)) // perimeter of the triangle
	area := (2 * s) + (p * c) // surface area of the triangular prism
	fmt.Printf("Surface Area: %.2f\n",area)
}
397 chars
17 lines

In this code, we first define the base length a, the height b, and the length of the prism c. We then calculate the area s of the triangle using the formula (base * height) / 2 and the perimeter p of the triangle using the Pythagorean theorem. Finally, we use the formula (2 * s) + (p * c) to find the surface area of the triangular prism.

This code outputs the surface area of the triangular prism as 31.98 for the given values of a, b, and c.

gistlibby LogSnag