Why does the first one work and the second doesn't?
#include <iostream> using namespace std; int main() { int n,num,rev=0,digit; cin>>num; n=num; do { digit=num%10; rev=(rev*10)+digit; num/=10; }while(num!=0); if (n==rev){ cout<<n<<" is a palindrome"; } else{ cout<<n<<" is not a palindrome"; } return 0; } This one work just fine #include <iostream> using namespace std; int main() { int num,rev=0,digit; cin>>num; while(num!=0){ digit=num%10; rev=(rev*10)+digit; num/=10; } if (num==rev){ cout<<num<<" is a palindrome"; } else{ cout<<num<<" is not a palindrome"; } return 0; } This one keeps giving me 0 as a value, and I have no Idea why.