To calculate the area and perimeter of common geometric shapes in Go, you can use the following formulas and implement them in your Go code:
package main
import (
"fmt"
"math"
)
func main() {
radius := 5.0
area := math.Pi * math.Pow(radius, 2)
perimeter := 2 * math.Pi * radius
fmt.Printf("Circle:\nArea: %f\nPerimeter: %f\n", area, perimeter)
}
package main
import "fmt"
func main() {
length := 5.0
width := 3.0
area := length * width
perimeter := 2 * (length + width)
fmt.Printf("Rectangle:\nArea: %f\nPerimeter: %f\n", area, perimeter)
}
package main
import "fmt"
func main() {
base := 4.0
height := 3.0
side1 := 5.0
side2 := 6.0
side3 := 7.0
area := (base * height) / 2
perimeter := side1 + side2 + side3
fmt.Printf("Triangle:\nArea: %f\nPerimeter: %f\n", area, perimeter)
}
You can customize the input values for each shape as per your requirement. The respective formulas will calculate the area and perimeter accordingly.