Palindrome Number Program in C++
Hello coder here we write
palindrome number program in c++ or some time you can get
C++ Program to Check Number is Palindrome or Not. To write this program first get input from use and revers this number, in next step compare output with original number, if both are same it means input number by user is palindrome otherwise not palindrome number.
Example of Palindrome number Program in C++
#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)
cout << " The number is a palindrome";
else
cout << " The number is not a palindrome";
return 0;
}
Output
Enter a positive number: 121
The reverse of the number is: 121
The number is a palindrome
Enter a positive number: 123
The reverse of the number is: 321
The number is not a palindrome
No comments :
Post a Comment