Welcome to my blog this is test

28 June 2012

5. write a C program to reverse a no. and check whether the reverse no. is a palindrome or not


//Code:
#include
#include
 void main()
  {
   long int a,s=0,n,p;
   clrscr();
   printf("\n Enter a number : ");
    scanf("%ld",&n);
            p=n;
       do
          {
           a=p%10;
           s=s*10+a;
           p=p/10;
          }
       while(p!=0);
            printf("\n The reverse no. is = %ld",s);
       if(n==s)
            printf("\n The reverse no. is a palindrom");
       else
            printf("\n The reverse no. is not a palindrom");
    getch();
  }

 /*Output:  
 Enter a number : 12345
 The reverse no. is = 54321
 The reverse no. is not a palindrom

 Enter a number : 1221
 The reverse no. is = 1221
 The reverse no. is a palindrom

No comments:

Post a Comment