Reverse a Four-Digit Number and Test for a Palindrome

Easy

Read a four-digit integer, reverse its digits with a loop, and print two lines: 1221 reversed is 1221 followed by 1221 is a palindrome, or 1234 reversed is 4321 followed by 1234 is not a palindrome. The reversal builds a number with reversed = reversed * 10 + n % 10 while peeling n with / 10, so a number ending in zeros reverses to a shorter number: 1200 reversed is 21. If the input is not between 1000 and 9999, print not a four-digit number and return 1. If it cannot be read, print invalid input and return 1.

Success Criteria

Your code must pass 8 test case(s) to complete this exercise. 3 hint(s) are available if you need help.

How did you find this exercise?

Your rating helps us improve the content.

Sign in to track your progress

You can work on exercises as a guest, but sign in to track your progress and save your submissions.

This platform is built by its community

Every lesson, project, and tool on HelloC++ is funded by sponsors. Join them and help shape what we build next.

Become a Patron