Can you Write a program in c++ to check the whether given number is palindrome or not using function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you Write a program in c++ to check the whether given number is palindrome or not using function

C++

19th Jan 2017, 10:55 AM
Aniket Deshmukh
2 Answers
+ 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; }
19th Jan 2017, 11:04 AM
bem
bem - avatar
+ 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; }
19th Jan 2017, 11:09 AM
Harsimran Kaur Bindra
Harsimran Kaur Bindra - avatar