Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

Enter any number:121

121 is a Palindrome Number.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write C++ program to print number in words... >>
<< Write C++ program to check whether a number is pal...