CODE OF GEEKS


A PLATFORM TO LEARN | CODE | ACHIEVE


" Programming is the real test of your creativity,its all about how you turn ideas into codes. "



Connect :


THIS WEBSITE IS BEST VIEWED IN THE GOOGLE CHROME WEB BROWSER.



TO CHECK WHETHER A GIVEN NUMBER IS PALINDROME OR NOT IN C++

Code

#include<iostream>
using namespace std;
int main()
{
int n,i;
int rem=0,rev=0;
int num=0;
cout<<"ENTER THE NUMBER ";
cin>>n;
num=n;
while(num>0)
{
  rem=num%10;
  rev=rev*10+rem;
  num=num/10;
}
if(n==rev)
{
  cout<<"YES IT IS THE PALINDROME NUMBER\n";		
}
else
{
cout<<"NO IT IS NOT THE PALINDROME NUMBER\n";		
}
return 0; 
}

Output


ENTER THE NUMBER :23432
YES IT IS THE PALINDROME NUMBER


What we did - Our Approach


In this problem we have to check whether the given number is a Palindrome or not.
A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed. Like 16461, for example, it is "symmetrical". Hence,it is quite clear that if a number is equal to its reversal then it is a palindrome number.

***FINDING THE REVERSE OF A NUMBER***
Let us consider an example :
Suppose we have to find the reverse of 535,we require three steps which needs to be performed under while loop condition (while n>0).
1 : Finding Remainder : rem=num%10
So, rem=535%10=5
2 : Finding Reverse : rev=rev*10+rem
So, rev=0+5
3 : Updating number : num=num/10;
So, num=53
But num>0, so we will perform above steps until 'num' gets equal to zero.After the last iteration we find rev=535.

***PALINDROME CHECKER***
Now we check whether the reverse of a number is equal to itself or not.In this case,535 is a Palindrome Number.

See this code in :


C

Java

Also see :


PROGRAM TO SWAP TWO NUMBERS USING XOR OPERATION

PROGRAM TO SWAP TWO NUMBERS USING THIRD VARIABLE

PROGRAM TO GENERATE THE SUM OF ALL DIGITS OF A NUMBER

PROGRAM TO FIND THE REVERSE OF A NUMBER

PROGRAM TO GENERATE THE FACTORIAL OF A NUMBER

PROGRAM TO EVALUATE THE SUM OF FIRST 'N' NUMBERS

Participate in our MONTHLY CHALLENGE,and get a chance to get listed on our site and win the TITLE of "MR.GEEK".


RUSH TO OUR MONTHLY CHALLENGE

Join us :



CODE OF GEEKS

A Platform to LEARN | CODE | ACHIEVE

Connect :



INTERESTING READ FOR YOU :

TOP PROGRAMMING LANGUAGES THAT ARE RULING IN 2018.
TOP PROGRAMMING LANGUAGES FOR WEB DEVELOPMENT IN 2018.

SHARE:



For any Queries,suggestions,feel free to Mail us at :
[email protected]

For reporting any kind of copyright voilation,mail us at : [email protected]

© copyright CODE OF GEEKS 2018