0
Can you Write a program in c++ to check the whether given number is palindrome or not using function
C++
2 Réponses
+ 5
bool isPalindrome(int num) {
int save = num;
int digit, reverse = 0;
do {
digit = num % 10;
reverse = (reverse * 10) + digit;
num = num / 10;
} while (num != 0);
return save == reverse;
}
+ 1
#include <iostream>
using namespace std;
int main() {
int n;
cout<<"Enter a number"<<endl;
cin>>n;
int y=n;
int d=0;
while(n!=0)
{
int r=n%10;
d=d*10 + r;
n=n/10;
}
cout<<"Reversed number= "<<d<<endl;
if(d==y)
cout<<"Palindrome";
else
cout<<"Not a Palindrome";
return 0;
}