GO Program to Check Whether a Number is Palindrome or Not


Simple program in go language using for...... loop to check whether an integer (entered by the user) is Palindrome or Not. if...else statement used to display final output.

Example

// Golang program to check whether a number is palindrome or not

package main
import "fmt"

func main() {
	var number,remainder,temp int
	var reverse int = 0

	fmt.Print("Enter any positive integer : ")
	fmt.Scan(&number)

	temp=number

	// For Loop used in format of While Loop
	for{
		remainder = number%10
		reverse = reverse*10 + remainder
		number /= 10

		if(number==0){
			break // Break Statement used to exit from loop
		}
	}

	if(temp==reverse){
		fmt.Printf("%d is a Palindrome",temp)
	}else{
		fmt.Printf("%d is not a Palindrome",temp)
	}

}
Most Helpful This Week