To check whether a given number is palindrome or not

This is the program to check for the ‘Palindrome’ property of the given number. Palindrome is the instinct property of any literal segment, where the segment reads the same either from left to right or vice versa.
For example : 12321 and  LEVEL  are the palindromes as they reads same if we go from right to left also.

Logic :  The program expects the user to enter the number to check if palindrome. The entered number is reversed and stored in another variable. Finally the reversed number is checked for equality with the entered number. If they are the same, then it is a palindrome.

A slight change in the code can check if the entered string is a palindrome.

#include<stdio.h>
#include<math.h>
void main()
{
long int n, num, rev = 0, dig;
clrscr();
printf(“\n\n\t ENTER A NUMBER…: “);
scanf(“%ld”, &num);
n = num;
while(num>0)
{
dig = num % 10;
rev = rev * 10 + dig;
num = num / 10;
}
if (n == rev)
printf(“\n\t GIVEN NUMBER IS A PALINDROME”);
else
printf(“\n\t GIVEN NUMBER NOT A PALINDROME”);
getch();
}
Download exe and source code here.

4 Responses to “To check whether a given number is palindrome or not”

  1. there is no need for including “math.h” rather than you should have included “conio.h” cause getch(); wont work without it, but the idea of reversing the number is amazing :)

    Reply
  2. c++ program to check the given number is a palindrome or not

    please send the 100% correct program

    Reply
  3. I am a Canadian, and I have a feeling of sororw and despair to see what is happening to our wonderful neighbor to the south. I think that the election of Barak Hussein Obama , was partly , an attempt to show that they had gone beyond the Black/white issue and that ,indeed ,any American born citizen had the opportunity to become President. If only the enquiring press had looked deeper into his background and discovered that he was NOT a loyal American , and worked against the Government as a community organizer in Chacago , and, like his beloved mentor and preacher for 20 yrs , Rev Wright, really hated America and wished to take it down. I also believe that , tho he was supposed to have come from very humble beginnings( raised by a penniless grandmother), etc, he was actually schooled and groomed by underground organizations funded by Socialists like GEORGE SOROS,and left wing underground groups like ACORNto evevtually bring America towards SOCIALIST WORLD GOVERNMENT !All I can do now is pray ( and I mean PRAY ), that Americans will wake up before these Socialis/ Communists have realized their ambition !!

    Reply

Leave a Reply