Go Program to Calculate Cube of a Number

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)
}
Golang Program to Find Cube of a Number 2

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.