Write a c++ program to check entered string is palindrome or not using while loop.
Answers
Hey there!
--------
Basic steps to check :
You have to first reverse the number and check whether reverse is equal to original or not. If it is equal then the number is palindrome, otherwise not palindrome number as i given here in the following program.
Here's your code :
/* Program to check if a number is palindrome or not using while loop and,
if statement is used to check whether the reversed number is equal to the original number or not. */
/* Program by : Mahnaz */
#include <iostream>
using namespace std;
int main()
{
int n, num, digit, rev = 0;
cout << "Enter any 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;
}
_____________________________
See the attachment for proper review.
_____________________________