C Code To Check Whether A No. Is Palindrome Or Not - Coding Bot

Like Us On Facebook

Follow Us On Twitter

Drop Down Menu

Thursday, 28 March 2013

C Code To Check Whether A No. Is Palindrome Or Not

A Palindrome number is a number, which when reversed in order of digits, produces the same number a the original one. Some examples of Palindrome numbers are: 11, 121, 1331. 14641, 15101051, 989, 5225 etc. The C program for the same is very simple. First we will reverse the original number and then check it with the original number. If found same, number is palindrome, otherwise not.

A Simple Algorithm for the same will be:
  1. Input number from user, 'num'.
  2. Apply Logic on 'num', produce reversed number 'rev'.
  3. If num == rev, print 'num' is Palindrome.
  4. Otherwise print 'num' is not Palindrome.

C Program To Check Whether A Number Is Palindrome Or Not:


/* Double-Click To Select Code */

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

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

 while(a!=0)
 {
  d = d*10;
  c = a%10;
  a = a/10;
  d = d+c;
 }

 if(d==b)
 printf("\nThe number %d is plaindrome",b);

 else
 printf("\nThe number %d is not Palindrome",b);

 getch();
}


Program Output:


Palindrome Number C Code


Please Comment If You Liked This Post !! 


Do you like this post? Please link back to this article by copying one of the codes below.

URL: HTML link code: Forum link code: