c++回文数取出6个数

标签 c++ algorithm palindrome

我需要编写代码来在屏幕上显示 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/

相关文章:

c++ - 右值引用可以作为 const 引用传递吗?

c++ - make_unique 可以存储文字或 iostream 输入吗?

c++ - 使用带有 char 数组参数的 strtok

c++ - 函数的两个版本不会产生相同的结果

python - 避免 Python RLE 算法中的差一错误

bash - 计算文本文件中的回文数

java - 创建一个函数,该函数返回重新排列为回文的数组字符串

java - Java 中 Int 的回文检查效率

c++ - 在没有 IDE 的情况下学习 C++

algorithm - 您是在递归算法中以广度优先还是深度优先进行搜索?