...
/Solution Review: Find out if the Given Number is a Palindrome
Solution Review: Find out if the Given Number is a Palindrome
Let's go over the solution review of the challenge given in the previous lesson.
We'll cover the following...
Solution #
Press + to interact
#include <iostream>using namespace std;int main() {// Initialize variableint number = 2002;int remainder = 0, reverse = 0;// To reverse a number store it in tempint temp = number;// while loopwhile (temp != 0) {// Get the last digit of tempremainder = temp % 10;// Store the remainder after the initially stored value in reversereverse = reverse * 10 + remainder;// Remove the last digit of temptemp = temp / 10;}// if conditionif (number == reverse) {cout << "is palindrome";} else {cout << "not a palindrome";}return 0;}
Explanation
To check if given the number is a palindrome or ...