find the area of a parallelogram in go

To find the area of a parallelogram, we need to know the base and height of the parallelogram. Then, we can use the formula:

main.go
Area = base * height
21 chars
2 lines

Here's a code snippet in Go that takes in the length of the base and height as input from the user and calculates the area of the parallelogram:

main.go
package main

import "fmt"

func main() {
    var base, height float64
    
    fmt.Print("Enter the length of the base: ")
    fmt.Scanln(&base)
    
    fmt.Print("Enter the height of the parallelogram: ")
    fmt.Scanln(&height)

    // Calculate the area of the parallelogram
    area := base * height

    fmt.Printf("Area of parallelogram with base %.2f and height %.2f is: %.2f", base, height, area)
}
409 chars
19 lines

In this Go code, fmt.Scanln is used to take user input for the base and height of the parallelogram. The area variable holds the result of the area calculation, and fmt.Printf is used to print out the final answer to the console. The .2f format specifier is used to round the result to two decimal places.

gistlibby LogSnag