Write a program in c++ to input a number and check if it is palindrome or not
Palindrome : A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.
#include <iostream>
using namespace std;
int main()
{
int n, num, ldigit, rev = 0;
cout << "Enter a Number : ";
cin >> n;
num = n;
while (num != 0)
{
ldigit = num % 10;
rev = rev * 10 + ldigit;
num /= 10;
}
if (rev == n)
{
cout << n << " is palindrome";
}
else
cout << n << " is not palindrome";
}
OUTPUT
1.
Enter a Number : 123454321
123454321 is palindrome
2.
Enter a Number : 345232
345232 is not palindrome
0 Comments:
Post a Comment