Palindrome Program In C++ - C++ Programming Tutorial
C++ Course / C++ Programs / Palindrome Program In C++

Palindrome Program In C++

BLUF: Mastering Palindrome Program In C++ is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Palindrome Program In C++

C++ is renowned for its efficiency. Learn how Palindrome Program In C++ enables low-level control and high-performance computing in the tutorial below.

A palindrome number remains the same when its digits are reversed, such as 121, 34543, 343, 131, and 48984.

Palindrome number algorithm

  • Get the number from user
  • Hold the number in temporary variable
  • Reverse the number
  • Compare the temporary number with reversed number
  • If both numbers are same, print palindrome number
  • Else print not palindrome number

Let's explore a C++ program that checks if a given number is a palindrome. This program prompts the user for an input and then verifies if the number remains the same when read from left to right and right to left.

Example

Example

#include <iostream>

using namespace std;

int main()

{

  int n,r,sum=0,temp;  

  cout<<"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:

Output

Enter the Number=121   

 Number is Palindrome.
Example

Enter the number=113  

Number is not Palindrome.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience