Go Program to reverse a number

In this program, you will learn how to reverse a number in Go.


for <condition> { 
    statement
    increment/decrement
}

Go Program to reverse a number

Example: How to reverse a number in Go

package main

import "fmt"

func main() {

	var n, r int
	fmt.Print("Enter a number:")
	fmt.Scan(&n)

	rev := 0
	for n > 0 {
		r = n % 10
		rev = rev*10 + r
		n = n / 10
	}

	fmt.Println("Reverse number is:", rev)
}

Output:

Enter a number:453
Reverse number is: 354