+ 1
Program to check whether the given number is palindrome or not
4 Réponses
+ 4
#include<iostream>
using namespace std;
int main()
{
int num,n,r,rev;
rev = 0;
cout<<"Enter the number: ";
cin>>num;
n = num;
while(n>0)
{
r = n%10;
rev = (rev*10)+r;
n = n/10;
}
if(num==rev)
cout<<"Number "<<num<<" is palindrome";
else
cout<<"Number "<<num<<" is not palindrome";
}
+ 3
Try that one
+ 2
when a number is reversed and it remains the same it is called palindrome number for example 22, 44
#include<iostream>
using namespace std;
int main()
{
int palindrome, reverse=0;
cout<<"Enter number: ";
cin>>palindrome;
int num=0,key=palindrome;
for(int i=1;palindrome!=0;i++){
num=palindrome%10;
palindrome=palindrome/10;
reverse=num+(reverse*10);
}
if(reverse==key){
cout<<key<<" is a Palindrome Number";
}
else{
cout<<key<<"is NOT a Palindrome Number";
}
return 0;
+ 1
but try a number which is greater than 10 digits .. it FAILS.😔