How to calculate the volume of a sphere in Go

1 Answer

0 votes
package main

import (
	"fmt"
	"math"
)

func sphereVolume(r float64) float64 {
	return 4.0 / 3.0 * math.Pi * math.Pow(r, 3)
}

func main() {
	radius := 5

	fmt.Println("Volume of sphere =", sphereVolume(float64(radius)))
}



/*
run:

Volume of sphere = 523.598775598299

*/

 



answered Sep 14, 2024 by avibootz

Related questions

1 answer 90 views
1 answer 119 views
1 answer 111 views
1 answer 98 views
1 answer 107 views
1 answer 104 views
1 answer 159 views
...