Palindromic Number in Go

Published on 08 October 2024 (Updated: 08 October 2024)

Welcome to the Palindromic Number in Go page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

package main

import (
	"fmt"
	"os"
	"strconv"
)

func palindromicNumber(x int) {
	if x >= 0 {
		reversedNumber := 0
		noOfDigits := 0
		temp := x

		for temp > 0 {
			noOfDigits++
			reversedNumber = (reversedNumber * 10) + (temp % 10)
			temp /= 10
		}

		if x == reversedNumber {
			fmt.Println("true")
		} else {
			fmt.Println("false")
		}
	} else {
		fmt.Println("Usage: please input a non-negative integer")
	}
}

func main() {
	if len(os.Args) < 2 {
		fmt.Println("Usage: please input a non-negative integer")
		os.Exit(1)
	}

	x, err := strconv.Atoi(os.Args[1])
	if err != nil {
		fmt.Println("Usage: please input a non-negative integer")
		os.Exit(1)
	}

	palindromicNumber(x)
}

Palindromic Number in Go was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.