Write a C++ Program to Check Whether a Number is Palindrome or Not

C++ Program to Check Whether a Number is Palindrome or Not

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C++ programming concepts. You can learn C++ language at your own speed and time. One can learn concepts of C++ language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Write a C++ Program to Check Whether a Number is Palindrome or Not

PROGRAM: C++ Program to Check Whether a Number is Palindrome or Not

/* C++ Program to Check Whether a Number is Palindrome or Not*/

#include <iostream>
using namespace std;

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

cout << “Enter a positive 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 and n > 0) // Negative numbers are not palindromic
cout << ” The number is a palindrome.”;
else
cout << ” The number is not a palindrome.”;

return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *