Thursday 6 September 2012

Loop control structure070

Input a number and check whether the number is palindrome or not.
N.B.: A number is said to be palindrome when its reverse number is equal to the original number. e.g. 121.

#include <stdio.h>
#include <conio.h>
void main ( )
{
           int       n, d, m, s = 0;
           clrscr ( );
           printf("\n\n\t\t\t Enter a number..:"); scanf("%d",&n);
                                         
           m = n;
           while ( n > 0)
           {                          
                         d = n % 10;
                         n = n / 10;
                         s = s * 10 + d;
           }                
                   
           if ( s == m )
           {                               
                         printf("\n\n\n\t\t\t The number is palindrome.");
           }                                       
           else              
           {                                                  
                         printf("\n\n\n\t\t\t The number is not palindrome.");
           }
           getch ( );
}
Click here to contact us 

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...