find the surface area of a cone in go

Here's an example code snippet in Go which calculates the surface area of a cone by taking the radius and height as inputs from the user:

main.go
package main

import (
    "fmt"
    "math"
)

func main() {
    var radius float64
    var height float64

    // Prompt user to enter radius and height
    fmt.Println("Enter the radius of the cone:")
    fmt.Scanln(&radius)
    fmt.Println("Enter the height of the cone:")
    fmt.Scanln(&height)

    // Calculate the slant height and surface area of the cone
    slantHeight := math.Sqrt(math.Pow(radius, 2) + math.Pow(height, 2))
    surfaceArea := math.Pi * radius * (radius + slantHeight)

    // Print the surface area of the cone
    fmt.Printf("The surface area of the cone is: %.2f", surfaceArea)
}
611 chars
25 lines

In this program, we first prompt the user to enter the radius and height of the cone. We then calculate the slant height of the cone using the Pythagorean theorem, and use it to find the surface area of the cone. Finally, we print the surface area with two decimal places using fmt.Printf().

gistlibby LogSnag