/* the thing is that i need to check if a given number (n) is a palindrome. i also used limits.h to identify if the number is

is exceeding the limit. i came up with this beut it's no good. any ideas? */

#include <iostream>

#include <stdlib.h>

#include <limits.h>

#include <math.h>

using namespace std ;

int main ()


int a, n, m=0, t ;

cout<<"Enter query number:"<<endl ;

cin>>n ;

t=n ;

  while (n)



       a=n%10 ;

       n=n/10 ;

       m=m*10+a ;


         if (INT_MAX-n<a)

         cout<<"overload" ;



if (t==m)

  cout<<t<<"this number is already a palindrome"<<endl ;


  cout<<t<<"this number is not a palindrome"<<endl ;


return 0 ;

4 Years
Discussion Span
Last Post by tinstaafl

One idea is to start by telling us what the program is and isn't doing right. Especially since aside from needing the output formatted better, this seems to do what you want.

Edited by tinstaafl


Well, it's printing "not a palindrome" for all the numbers i punch
Including many palindromes..


you need to move the curly brace from line 60 to line 49 to put the if statement on line 50 outside your while loop.


I think you'll find that you're getting a number of not a palindrome statements, but if you look closely the last one will say it is a palindrome if it is one. Moving the curly brace,}, as was mentioned should clear that up.

The code works when I test it.

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.