0
Write a program in c++ to find whether a number is a palindrome number or not
please use only while statement
4 ответов
+ 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;
}
+ 6
but I don't know what a palindrome is...
and I don't know how I passed high school math!
+ 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();
}
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;
}