Skip to content

Palindrome number

C++ reversing a number

Flowchart (ISO 5807)

YesNoStartInput nrev = 0t = nt > 0rev = rev·10 + t mod 10t = t / 10Return rev = nEndFigure 1 — isPalindrome

Source code

C++
bool isPalindrome(int n) {
    int rev = 0;
    int t = n;
    while (t > 0) {
        rev = rev * 10 + t % 10;
        t /= 10;
    }
    return rev == n;
}

The editor opens with this code — change it and the chart redraws.

Language
C++
Constructs
reversing a number
Topic
Algorithms
Formats
Word, Visio, draw.io, PDF, SVG

Related examples