# reverse a number using recursion in golang

Go program for reverse a number using recursion . Here problem description and explanation.

``````// Go program for
// Reverse a number using recursion
package main
import "fmt"

// This is reversing a number elements recursively
func reverseNum(number, result int) int {
// Base condition to stop the recursion process
if number > 0 {
// Recursive function call
return reverseNum(number / 10,
result * 10 + (number % 10))
}
// When no digit remaining
return result
}
// This is handling the request process of reverse number digit
func reverse(number int) int {
// Display given number
fmt.Println("\nBefore Number : [", number, "]")
if number < 0 {
// Handle negative number
return -reverseNum(-number, 0)
} else {
return reverseNum(number, 0)
}
}
func main() {

// Test Case
var number int = 12345
number = reverse(number)
// After reverse
fmt.Println("After Number  : [", number, "]")
number = reverse(78942)
// After reverse
fmt.Println("After Number  : [", number, "]")
number = reverse(1020)
// After reverse
fmt.Println("After Number  : [", number, "]")
number = reverse(-28)
// After reverse
fmt.Println("After Number  : [", number, "]")
}``````

Output

``````Before Number : 
After Number  : 

Before Number : 
After Number  : 

Before Number : 
After Number  : 

Before Number : [-28]
After Number  : [-82]``````

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.