Palindrome Number program in C++

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this Basic C++ Program, we will have a look at how to write a C++ program to check the palindrome number.

A palindrome number is a number that is the same after reversing. For example, 121, 34543, 343, 131, 48984 are the palindrome numbers.

Algorithm Of Palindrome Number

  • Get the user number
  • Keep the number in the temporary variable
  • Reverse the number
  • Compare the temporary number with the number invested
  • If both numbers are the same, print the palindrome number.
  • Otherwise, the palindrome number is not printed

Let’s have a look at the palindrome program in C ++. In this program, we will obtain a user input and we will check if the number is a palindrome or not.

C++ Program To Check The Palindrome Number.

#include <iostream>  

using namespace std;  

int main()  

{  

  int n,r,sum=0,temp;    

  cout<<"Please enter the Number=";    

  cin>>n;    

 temp=n;    

 while(n>0)    

{    

 r=n%10;    

 sum=(sum*10)+r;    

 n=n/10;    

}    

if(temp==sum)    

cout<<"Number is Palindrome.";    

else    

cout<<"Number is not Palindrome.";   

  return 0;  

Output:

Please enter the Number=121

Number is Palindrome.

 

Please enter the number=113

Number is not Palindrome.

Leave a Comment

Your email address will not be published. Required fields are marked *