我需要编写代码来在屏幕上显示 6 个回文数字。
示例: 300003 310013 320023 330033 340043 350053.
调查结果: 到目前为止,我刚刚编写了如何检查其回文数的代码。
这是我如何检查它是否回文的代码:
#include <iostream>
using namespace std;
int main()
{
int n, num, dig, rev = 0;
cout << "Insert number": "<< endl;
cin >> num;
n = num;
while (num != 0);
{
dig = num % 10;
rev = (rev * 10) + dig;
num = num / 10;
}
if (n == rev)
cout << "This is palindrome "<< rev << endl;
else
cout << "This is not palindrome "<< rev << endl;
return 0;
}
你们能给我一些想法吗?
最佳答案
你陷入了一个无限的 while 循环中:
while (num != 0);
所以去掉分号就可以了。
关于c++回文数取出6个数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46735509/