Palindromic Number in C++

Published on 01 November 2021 (Updated: 15 April 2026)

Welcome to the Palindromic Number in C++ page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>

using namespace std;

void palindromic_number(int number)
{
    int temp = number, reversed_number = 0;

    while (temp > 0)
    {
        reversed_number = (reversed_number * 10) + (temp % 10);
        temp = (int)(temp / 10);
    }
    if (number < 0)
    {
        cout << "Usage: please input a non-negative integer";
        exit(1);
    }
    else
    {
        if (reversed_number == number)
            cout << "true";
        else
            cout << "false";
    }
}

int is_int(char **argv)
{
    int j = 0;
    while (isdigit(argv[1][j]))
        ++j;

    if (strlen(argv[1]) != j || j == 0)
        return 1;
    else
        return 0;
}

int main(int argc, char **argv)
{
    if (argc != 2 || is_int(argv))
    {
        cout << "Usage: please input a non-negative integer";
        return (1);
    }
    palindromic_number(atoi(argv[1]));
    return (0);
}

Palindromic Number in C++ was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.