Here, we will see program to convert decimal number to Octal in go. Given below, you can find algorithm and program.
To convert decimal number to octal number, we will use FormatInt() function of strconv package.
Input: num = 10
Octal number = 12
Input: 4
Octal number = 4
Input: 15
Octal number = 17
Code:
package main
import (
"fmt"
"strconv"
)
func main() {
var num int64
num = 10
oct_num := strconv.FormatInt(num, 8)
fmt.Println("octal num: ", oct_num)
num = 4
oct_num = strconv.FormatInt(num, 8)
fmt.Println("octal num: ", oct_num)
num = 15
oct_num = strconv.FormatInt(num, 8)
fmt.Println("octal num: ", oct_num)
}
Output:
octal num: 12 octal num: 4 octal num: 17
To learn more about golang. Please follow given below link.
https://techieindoor.com/go-lang/
References:
https://golang.org/doc/ https://golang.org/pkg/