Write C++ program to check whether a number is palindrome or not

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.

#include <iostream>
 
using namespace std;
 
int main()
{
    int num, i, rev;
 
    //Reading a number from user
    cout<<"Enter any number:";
    cin>>num;
 
    rev = num;
    for(i=0; num>0; num=num/10)
    {
        i = i * 10;
        i = i + (num%10);
    }
     //Checking if reverse number is equal to original num or not.
    if(rev == i)
       cout<< rev << " is a Palindrome Number.";
    else
        cout<< rev << " is not a Palindrome Number.";
 
   return 0;
}

Result

Write C++ program to check whether a number is palindrome or not
Write C++ program to check whether a number is palindrome or not

Leave a Comment