Saturday, June 29, 2013

Write a C program to test Palindrome Numbers.



#include <stdio.h>
 
void main()
{
   int n, rev = 0, temp;
 
   printf("Enter a number to check if it is a palindrome or not\n");
   scanf("%d",&n);
 
   temp = n;
 
   while( temp != 0 )
   {
      rev = rev * 10;
      rev = rev + temp%10;
      temp = temp/10;
   }
 
   if ( n == rev )
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d is not a palindrome number.\n", n);
 }

No comments:

Post a Comment