Check Palindrome Number
“Check Palindrome Number” is very basic and important programming exercise problem. Here, we are given an integer, entered by user and our task is to write a program to check whether an entered number is palindromic number or not.
A palindromic number is a number which is when reversed stays the same number.
Examples of Palindromic Number are 22, 212, 33433 etc.
The steps required to check palindrome number are as follows:
- Scan a number from a user and copy that number to temporary variable.
- Initialize a reverse_number with 0.
- Now, one by one fetch out the last digit from a number using modulus operator and concatenate to reverse_number.
- Now, check whether reversed_number and temporary variable number are same or not.
- If they are same, then given number is palindromic number. Else, given number is not palindromic number.
C++ Program to check palindrome number is as follows:
/* C++ Program to check palindrome number */ #include<bits/stdc++.h> using namespace std; int main() { //Scan the number int num; cout<<"Enter the number:"; cin>>num; // Reverse the number int temp = num; int reverse = 0; while(temp > 0) { int digit = temp % 10; reverse = reverse*10 + digit; temp = temp/10; } // Check Palindrome number if(num == reverse) cout<<num<<" is Palindromic Number"; else cout<<num<<" is not Palindromic Number"; }
OUTPUT: Enter the number:7117 7117 is Palindromic Number
Related Posts:
- Program to find and print nth Fibonacci number.
- Program to find Power of the Number.
- Program to find Quotient and Remainder.
- Program to find largest amongst three numbers.
- Program to find factorial of a number.
- Program to find GCD of two numbers.
- Program to find LCM of two numbers.
- Program to check whether entered number is odd or even.
- Program to check whether entered number is prime number or not.
- Program to check whether entered number is Armstrong Number or Not.
- Program to convert binary number to octal number.
- Program to convert binary number to decimal number.
- Program to convert binary number to hexadecimal number.
- Program to convert octal number to binary number.
- Program to convert octal number to decimal number.
- Program to convert octal number to hexadecimal number.
- Program to convert decimal number to binary number.
- Program to convert decimal number to octal number.
- Program to convert decimal number to hexadecimal number.
- Program to convert hexadecimal number to binary number.