[Golang]Area of a circle

Another exercise on golang, experience in python helps me pick up golang rather quickly.

calculate the area of a circle.

package main

import (
	"fmt"
	"math"
)

func area(radius float64) float64 {
	return math.Pi * radius * radius
}

func main(){
	var r float64
	fmt.Println("Enter radius: ")
	fmt.Scanf("%f", &r)
	a := area(r)
	fmt.Printf("The radius is %f and the area is %f.", r, a)
}

circle1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s