This go program to calculate the cube of a number, we used arithmetic operator (multiplication) to find the cube.
package main
import "fmt"
func main() {
var num int
fmt.Print("Enter the Number to find Cube = ")
fmt.Scanln(&num)
cube := num * num * num
fmt.Println("\nThe Cube of a Given Number = ", cube)
}
Enter the Number to find Cube = 7
The Cube of a Given Number = 343
In this Golang program, we declared a function that accepts an integer and returns the number’s cube. Next, within the main program, we call that find_cube function.
package main
import "fmt"
func find_cube(x int) int {
return x * x * x
}
func main() {
var num int
fmt.Print("Enter the Number to find Cube = ")
fmt.Scanln(&num)
cube := find_cube(num)
fmt.Println("\nThe Cube of a Given Number = ", cube)
}
