C Program to Check Whether a Number is Palindrome or not

Writing a C program to check whether a number is palindrome or not is a beginner-level yet essential programming task. A palindrome number is a number that remains the same when its digits are reversed. For Example-121, 131, 1331, etc are all palindrome numbers because they read the same from left to right as well as right to left.

LRU Page Replacement Algorithm in C

Problem Statement

Write a C program to check whether a number is palindrome or not.

C Program to Check Palindrome Number

Let’s write a C program that checks whether the given number is a palindrome or not.

Output

C Program to Check Palindrome Number

How the Above C Program Works

  • The palindrome function takes an integer as an argument and returns 1 if the number is palindrome otherwise it returns 0.
  • Inside the palindrome function, we store the original number in the original, and a variable reverse is initiated to store the reversed number.
  • The while loop is used to reverse the digits of the number by extracting the remainder when divided by 10 and building the reverse number.
  • After reversing the number if the original number and reverse number are equal then the isPalindrome function returns 1(true) otherwise it returns 0(false).
  • Inside the main method, isPalindrome function is called, and based on its return value the program prints whether the given number is palindrome or not.

The concept used in this article to check whether a number is palindrome or not can be implemented in all other programming languages like C++, Java, Python, Go, etc.

Happy Coding

See Also

1 thought on “C Program to Check Whether a Number is Palindrome or not”

Leave a Comment