Back In the print window choose "Save as PDF" as the destination
NOTE.CS

Palindrome Number

1 topic · 28 Nov 2026
1

Palindrome Number

Problem Solving

A number is a palindrome if it reads the same backwards. Example: 121, 1331

Solution 1: Reverse and compare · C++
int n = 121, temp = n, rev = 0;
while(temp != 0){
    rev = rev * 10 + temp % 10;
    temp /= 10;
}
cout << (rev == n ? "Palindrome" : "Not Palindrome");
Solution 2: Palindrome string (two pointers) · C++
string s = "madam";
bool ok = true;
for(int i = 0, j = s.size() - 1; i < j; i++, j--)
    if(s[i] != s[j]) { ok = false; break; }
cout << (ok ? "Palindrome" : "Not Palindrome");