Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

Program to check whether a Number is a Palindrome

Below is a program to check whether a number is a palindrome or not.

A palindrome is a number or a string which is similar when read from the front and from the rear. For example: 121 or Oppo etc.


void main()
    int a, b, c, s = 0;
    printf("Enter a number:\t");
    scanf("%d", &a);
    c = a;

   // the number is reversed inside the while loop.
   while(a > 0)
      b = a%10;
      s = (s*10)+b;
      a = a/10;

   // here the reversed number is compared with the given number.
   if(s == c)
      printf("The number %d is a palindrome", c);
      printf("The number %d is not a palindrome", c);

Enter the number: 121 The number 121 is a palindrome