fabbe680

2.3

Jan 19th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. // Laboration 2, Assignment_3.cpp
  2. // Fabian Tjernström (fatj1700) 2018-11-21
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.  
  10. int num, copyNum, digitCount = 0, rem = 0, revNum = 0;
  11.  
  12. cout << "This is a program to check if a number is a palindrome." << endl;
  13. cout << "Enter a five digit number: ";
  14. cin >> num;
  15.  
  16. copyNum = num;
  17.  
  18. while( copyNum > 0 ) {
  19. copyNum = copyNum / 10;
  20. digitCount++;
  21. }
  22.  
  23. if( digitCount < 5 ) {
  24. cout << "Too FEW digits!" << endl;
  25. }
  26. else if( digitCount > 5 ) {
  27. cout << "Too MANY digits!" << endl;
  28. }
  29. else {
  30. copyNum = num;
  31. while( copyNum != 0 ) {
  32. rem = copyNum % 10;
  33. revNum = revNum * 10 + rem;
  34. copyNum /= 10;
  35. }
  36. if ( revNum == num ) {
  37. cout << "Your number is a palindrome!" << endl;
  38. }
  39. else {
  40. cout << "Sorry, your number is NOT a palindrome." << endl;
  41. }
  42. }
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment