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

Write a program in c++ to find whether a number is a palindrome number or not

please use only while statement

12th May 2017, 9:28 AM
Bhavya Gupta
Bhavya Gupta - avatar
4 Answers
+ 9
/* palindrom means that if the reverse of the number is the same of the original number. ex: 34543 --(reverse)-> 34543 , is palindrome but 123 --(reverse)-> 321 , not equal then it is not palindrome */ #include <iostream> using namespace std; int main() { int n,temp; int rev=0; cout<<"insert a number: "; cin>>n; temp=n; while (temp != 0){ rev *= 10; rev = rev + temp%10; temp /=10; } if(n == rev){ cout << n << " is a palindrome" << endl; }else cout << n << "not a palindrome"; return 0; }
12th May 2017, 1:20 PM
Mohammad Dakdouk
Mohammad Dakdouk - avatar
+ 6
but I don't know what a palindrome is... and I don't know how I passed high school math!
12th May 2017, 9:58 AM
Ahri Fox
Ahri Fox - avatar
+ 2
Dear #include<iostream> using namespace std; class palindrome { int num, temp, rem, revs; public: palindrome(int x) { num=x; revs=0; } void calc() { temp=num; while(temp!=0) { rem=temp%10; revs=revs*10+rem; temp/=10; } } void verify() { if(num==revs) { cout << num << " is a palindrome" << endl; } else { cout << num<< " is a NOT palindrome" << endl; } } }; int main() { int x; cin >> x; palindrome P(x); P.calc(); P.verify(); }
4th Jan 2021, 11:03 PM
Phillip Scott
Phillip Scott - avatar
0
#include <iostream> using namespace std; int main() { int n,temp; int rev=0; cout<<"insert a number: "; cin>>n; temp=n; while (temp != 0){ rev *= 10; rev = rev + temp%10; temp /=10; } if(n == rev){ cout << n << " is a palindrome" << endl; }else cout << n << "not a palindrome"; return 0; }
25th Jan 2021, 7:24 AM
Emmanuel C Crizillion
Emmanuel C Crizillion - avatar