Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Laboration 2, Assignment_3.cpp
- // Fabian Tjernström (fatj1700) 2018-11-21
- #include <iostream>
- using namespace std;
- int main() {
- int num, copyNum, digitCount = 0, rem = 0, revNum = 0;
- cout << "This is a program to check if a number is a palindrome." << endl;
- cout << "Enter a five digit number: ";
- cin >> num;
- copyNum = num;
- while( copyNum > 0 ) {
- copyNum = copyNum / 10;
- digitCount++;
- }
- if( digitCount < 5 ) {
- cout << "Too FEW digits!" << endl;
- }
- else if( digitCount > 5 ) {
- cout << "Too MANY digits!" << endl;
- }
- else {
- copyNum = num;
- while( copyNum != 0 ) {
- rem = copyNum % 10;
- revNum = revNum * 10 + rem;
- copyNum /= 10;
- }
- if ( revNum == num ) {
- cout << "Your number is a palindrome!" << endl;
- }
- else {
- cout << "Sorry, your number is NOT a palindrome." << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment