Palindrome number:
A number is said to palindrome if the digits of the number is reversed and it still remain the same.
Example:
- Digits from 0 to 9 are all palindrome
- 11, 22, 33, 44, 121, 383, 12321, etc.
- Start the program
- Input a number to check palindrome or not
- Initialize the remainder variable to 0
- Divide the input number by 10 and store its remainder on a variable
- Store the quotient on the palindrome variable.
- Reverse the number and compare with the original input number
- If the reversed number is equivalent to original then it is palindrome otherwise not palindrome.
#include"iostream" using namespace std; int main() { int palindrome, reverse=0; cout<<"Enter a number: "; cin>>palindrome; int num=0,key=palindrome; for(int i=1; palindrome!=0; i++) { num = palindrome % 10; palindrome=palindrome / 10; reverse=num+(reverse*10); } if(reverse==key) { cout<<key<<" is a Palindrome number"; } else { cout<<key<<" is not a Palindrome Number"; } return 0; }
INPUT : Enter a number: 135
OUTPUT: 135 is not a Palindrome Number
INPUT : Enter a number: 52325
OUTPUT: 52325 is a Palindrome Number
No comments:
Post a Comment