NUMBER PALINDROME OR NOT USING DO WHILE LOOP IN C++
#include <iostream>
using namespace std;
int main ()
{
int num, temp1, temp2, rev = 0;
cout<<"PLEASE ENTER A NUMBER : ";
cin>>num;
temp2 = num;
do
{
temp1 = num % 10;
rev = rev * 10 + temp1;
num = num / 10;
} while (num != 0);
if (temp2 == rev)
{
cout<<"THIS IS PALINDROME"<<endl;
}
else
{
cout<<"THIS IS NOT PALINDROME"<<endl;
}
return 0;
}
using namespace std;
int main ()
{
int num, temp1, temp2, rev = 0;
cout<<"PLEASE ENTER A NUMBER : ";
cin>>num;
temp2 = num;
do
{
temp1 = num % 10;
rev = rev * 10 + temp1;
num = num / 10;
} while (num != 0);
if (temp2 == rev)
{
cout<<"THIS IS PALINDROME"<<endl;
}
else
{
cout<<"THIS IS NOT PALINDROME"<<endl;
}
return 0;
}
OUTPUT
No comments