- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a Golang program to check whether a given number is a palindrome or not
Definition: A palindrome is a number which is similar when read from the front and from the rear.
Examples
- num = 121 => Palindrome
- num = 13131 => Palindrome
- num = 123 => Not a Palindrome
Approach to solve this problem
- Step 1: Define a function that accepts a numbers(num); type is int.
- Step 2: Start making the number from the input number.
- Step 3: If the given number is same as the output number, then return “Palindrome”
- Step 4: Else, return “Not A Palindrome”
Program
package main import "fmt" func checkPalindrome(num int) string{ input_num := num var remainder int res := 0 for num>0 { remainder = num % 10 res = (res * 10) + remainder num = num / 10 } if input_num == res { return "Palindrome" } else { return "Not a Palindrome" } } func main(){ fmt.Println(checkPalindrome(121)) fmt.Println(checkPalindrome(123)) fmt.Println(checkPalindrome(1331)) fmt.Println(checkPalindrome(1231)) }
Output
Palindrome Not a Palindrome Palindrome Not a Palindrome
- Related Articles
- Write a Golang program to check whether a given number is prime number or not
- C++ Program to Check Whether a Number is Palindrome or Not
- Write a C# program to check if a number is Palindrome or not
- Golang Program to check a given number is finite or not
- Write a Golang program to check whether a given array is sorted or not (Using Bubble Sort Technique)
- 8085 program to check whether the given 16 bit number is palindrome or not
- Golang Program to check if the binary representation of a number is palindrome or not
- Python Program to Check Whether a String is a Palindrome or not Using Recursion
- Golang program to check if k’th bit is set for a given number or not.
- C++ Program to Check Whether a Number is Prime or Not
- C Program to Check Whether a Number is Prime or not?
- Java Program to Check Whether a Number is Prime or Not
- How to Check Whether a String is Palindrome or Not using Python?
- Program to check whether inorder sequence of a tree is palindrome or not in Python
- Java program to check whether a given string is Heterogram or not

Advertisements