这个Go语言程序用于计算数字的立方,我们使用算术运算符(乘法)来求立方。
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
在这个Golang程序中,我们声明了一个接受整数并返回该数字立方值的函数。接下来,在主程序中,我们调用了find_cube函数。
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)
}
