This program will find out if the number entered by the user is a palindromic number.
A palindromic number or numeral palindrome is a ‘Symmetrical’ number like 16461, that remains the same when its digits are reversed.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include <iostream> //Including iostream in our program. void main() { using namespace std; int num,rem,sum=0,numCopy; //Defining variables. cout <<"Enter a number:"; // Ask user for input. cin>>num; numCopy=num; while(num!=0) //Loop to reverse the number. { rem=num%10; num=num/10; sum=sum*10+rem; } //Result Display: if(numCopy==sum) { cout<<"The number you entered is a Palindrome."<<endl; } else { cout<<"The number you entered is not a Palindrome."<<endl; } cin.get(); cin.get(); } |
Tested in Compiler: Visual C++.
Vlad
Latest posts by Vlad (see all)
- Code jam “Tic-Tac-Toe-Tomek” solution in java - April 19, 2013
- Code jam “Minimum Scalar product” solution in java - March 18, 2013
- Code jam Store Credit solution in java - March 10, 2013