Search C Program | nimishsoft@gmail.com

Palindrome Number


/* Palindrome number using while loop */
#include <stdio.h>
int main()
{
 int n, r = 0,t;
 
 printf("Please enter a number: ");
 scanf("%d",&n);

 t=n;
 while (n > 0)
 {
  r = r * 10;
  r = r + n%10;
  n = n/10;
 }
 
 if(t==r)
  printf("Number is Palindrome");
 else
  printf("Number is not Palindrome");
  
 return 0;
}

------------------------------------------------------------------

/* Palindrome number using for loop */
#include <stdio.h>
int main()
{
 int n, r, t;
 
 printf("Please enter a number: ");
 scanf("%d",&n);
 
 t=n;
 for(r=0;n>0;n=n/10)
 {
  r = r * 10;
  r = r + n%10;
 }
 
 if(t==r)
  printf("Number is Palindrome");
 else
  printf("Number is not Palindrome");
  
 return 0;
}

Related Links:
Reverse Number
http://cbasicprogram.blogspot.in/2012/05/reverse-number.html

Sum of digits
http://cbasicprogram.blogspot.in/2012/05/sum-of-digits.html

3 comments:

  1. write a program in CIPHER TEXT.

    ReplyDelete
  2. If we need to check whether a 3 digit number is a palindrome number, then just compare the 1st digit and 3rd digit. If they are equal, then declare as palindrome number.

    ReplyDelete