8.08.2012

Reverse number and check palindrome or not

Q. Write a C program to accept any number from user and reverse it. Also find it that number is palindrome or not.

for example:

number- 12345
result- 
        reverse:54321
        number is not palindrome

Ans.

/*c program for reverse a given number and check it for palindrome or not*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,rem,n,rev=0;
 printf("Enter any number: ");
 scanf("%d", &num);
 for(n=num; n!=0; n=n/10)
 {
    rem = n%10;
    rev = rev*10+rem;
 }
 printf("\nEntered number in reverse order: %d\n",rev);
 if(rev==num)
    printf("%d is Palindrome.", num);
 else
    printf("%d is not Palindrome.", num);
 getch();
 return 0;
}

/************Output************/

Output of reverse number and number is not palindrome C program
Screen shot for reverse number and number
 is not palindrome C program

Output of reverse number and number is palindrome C program
Screen shot for reverse number and number
 is palindrome C program

2 comments:

  1. hi need to print between 1 to 10000 palindrom numbers.. how to do... can u send me the pgm
    sudharshank.bca@gmail.com

    thnks

    ReplyDelete
  2. hey, can you plz give algorithm of this question.

    ReplyDelete