I created a program to calculate volume of hemisphere using go ,the program is printing the volume as zero :
package main
import (
"fmt"
"math"
)
func volumeHemisphere(radius float64) float64 {
return 2 / 3 * math.Pi * math.Pow(radius, 3)
}
func main() {
fmt.Println(volumeHemisphere(2.0))
}
CodePudding user response:
Modify your code as float64(2)/float64(3)* math.Pi * math.Pow(radius, 3)
package main
import (
"fmt"
"math"
)
func volumeHemisphere(radius float64) float64 {
return float64(2) / float64(3) * math.Pi * math.Pow(radius, 3)
}
func main() {
fmt.Println(volumeHemisphere(2))
}
Output:
16.755160819145562