Check whether number is palindrome or not
Problem:
Solution:
# include <iostream>
using namespace std;
int main()
{
int n;
int r=0;
int temp;
cout << "Please enter an Integer : ";
cin >> n;
temp = n;
while (n > 0)
{
r = r * 10 + n % 10;
n = n / 10;
}
if (temp == r)
{
cout << "Integer " << temp << " is a Palindrome" << endl;
}
else
{
cout << "Integer " << temp << " is a not a Palindrome" << endl;
}
system("pause");
return 0;
}
W rite program that a number from user(an integer)
and finds that whether it’s PALINDROME or not.
Note:(PALINDROME Number is that
which has same sequence of numbers when reading from both left and right side. In
simple words,
1st
digit is
same as Last digit
2nd digit is same as 2nd Last digit
and so on.
E-g, 22,333,141,5115,10001 etc.)
Sample Output
(1)-
Enter
a number : 121121
Result
: Yes It’s a Palindrome number
# include <iostream>
using namespace std;
int main()
{
int n;
int r=0;
int temp;
cout << "Please enter an Integer : ";
cin >> n;
temp = n;
while (n > 0)
{
r = r * 10 + n % 10;
n = n / 10;
}
if (temp == r)
{
cout << "Integer " << temp << " is a Palindrome" << endl;
}
else
{
cout << "Integer " << temp << " is a not a Palindrome" << endl;
}
system("pause");
return 0;
}
Case 1 |
Case 2 |