Knowee
Questions
Features
Study Tools

Write a C++ program to check if a given number is a palindrome. A palindrome is a number that remains the same when its digits are reversed.

Question

Write a C++ program to check if a given number is a palindrome.

A palindrome is a number that remains the same when its digits are reversed.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple C++ program that checks if a given number is a palindrome:

#include <iostream>
using namespace std;

int main() {
    int n, num, digit, rev = 0;

    cout << "Enter a number: ";
    cin >> num;

    n = num;

    do {
        digit = num % 10;
        rev = (rev * 10) + digit;
        num = num / 10;
    } while (num != 0);

    cout << "The reverse of the number is: " << rev << endl;

    if (n == rev)
        cout << "The number is a palindrome.";
    else
        cout << "The number is not a palindrome.";

    return 0;
}

This program works by reversing the digits of the input number and then comparing the reversed number with the original number. If they are the same, then the number is a palindrome.

This problem has been solved

Similar Questions

Write a program in java to accept a number and chech whether it is a palindrome number or not. Do the program without using modulus operator and String.

Write a programme to check whether given input is palindrome or notConstraintsABC != PalindromeMAM == Palindrome123 != Palindrome151 == Palindrome

Write a program in C to print a string in reverse using a character pointer.Also print the uppercase of the first letter of the reversed word.

Write a Java program to check whether a given word is a palindrome or not. for e.g. MADAM is a palindrome but eat is not.

Write a C++ program to find Reverse of a Number using class.inputEnter a number: 12345output54321

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.