Go Program to check a number is palindrome or not
In this program, you will learn how to check a number is palindrome or not in Go.
for <condition> {
statement
increment/decrement
}
Example: How to check a number is a palindrome or not in Go
package main
import "fmt"
func main() {
var n, r, num int
fmt.Print("Enter a number:")
fmt.Scan(&n)
num = n
rev := 0
for n > 0 {
r = n % 10
rev = rev*10 + r
n = n / 10
}
if num == rev {
fmt.Println("Number is palindrome:", num)
} else {
fmt.Println("Number is not palindrome:", num)
}
}
Output:
Enter a number:121
Number is palindrome: 121