/*
david ballantyne
10/10/13
assesment lab 2
*/
//Libraries
#include <iostream>
//Global Constants
//Functioning Prototypes
using namespace std;
int main() {
int n, num, digit, rev = 0;
cout << "Enter a positive number"<<endl;
cin >> num;
num=n;
do{
digit = num%10;
rev = (rev*10) + digit;
num = num/10;
}
while (num!=0);
if (n == rev)
cout << " The number is a palindrome"<<endl;
else
cout << " The number is not a palindrome"<<endl;
return 0;
}
我输入了一个回文,它一直告诉我这不是一个回文,如果你能帮助我理解我会用什么样的循环来询问“你想再试一次是吗”,我将不胜感激.
最佳答案
将数字转换为字符串可能更容易。创建一个与第一个字符串相反顺序的新字符串。然后比较一下看是不是一样的。真的没有理由做任何真正的数学,回文是词汇的,而不是数学的。
关于c++ - 检查数字是否是 C++ 中的回文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19301819/