What is a palindrome numbers?

Palindrome numbers are those numbers which remain same after reverse. Think about the number 1221. If we reverse the number then the value will be same as 1221. This type of numbers are called palindrome numbers. Some palindrome numbers are 11,  55,  121,  363,  25652 etc.

In this C++ programming article we will see C++ program related to palindrome numbers. We already have discussed about palindrome numbers in C programming. Now, let’s try to understand palindrome number program in C++.

C++ program to check palindrome numbers

Let’s see the algorithm to check whether a number is palindrome or not which we will apply here.

  • Take the number from user and store it to a variable
  • Reverse the number and compare with the given number.
  • If they are same, print the number is palindrome
  • Otherwise print the number is not a palindrome number.

Now, Let’s see the C++ source code bellow;

// c++ program to check palindrome number

#include <iostream>
using namespace std;

int main(){
    int main_num, temp_num, rem, sum = 0;

    cout << "Enter the number here : ";
    cin >> main_num;
    temp_num = main_num;

    while(main_num > 0){
        rem = main_num % 10;
        sum = (sum * 10) + rem;
        main_num /= 10;
    }

    if(temp_num == sum){
        cout << "\n" << temp_num << " is a palindrome number." << endl;
    }else{
        cout << "\n" << temp_num << " is not a palindrome number." << endl;
    }

    return 0;

}

Output of palindrome number program:

palindrome-numbers-in-c-check-palindrome-numbers-using-c
palindrome-numbers-in-c-c-program-to-check-palindrome-numbers

Previous pageFibonacci series

Next pageSize of variables