C Program to check whether a Number is a Palindrome

5 (100%) 2 votes

C Program to check whether a Number is a Palindrome

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.

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

#include<stdio.h>
#include<conio.h>

void main()
{
    int a, b, c, s = 0;
    clrscr();
    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);
   }
   else
   {
      printf("The number %d is not a palindrome", c);
   }
  getch();
}

Output:

Enter the number: 121 

The number 121 is a palindrome


For any query or issue, feel free to discuss on http://discuss.eduguru.in
%d bloggers like this: