Program to check for a palindrome number


# include <iostream.h>
# include<conio.h>
#include<string.h>
#include<stdlib.h>
void main( )
{
    int num, n, flag = 0, i=0;
    char s[10];

    cout<<"\n Input an integer : ";
    cin>>num;

    itoa (num,s,10);           //convert int to string
    n = strlen(s) -1;
    while(s[i] != '\0')
    {
            if (s[i] != s[n-i])
        {
                 flag = 1;
             break;
        }
               i++;
    }
    if (flag == 1)
               cout<<"\n Number is not Palindrome";
    else
                 cout<<"\n Number is Palindrome";
    getch( );
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|