C++实现判断一个区间内的所有回文数,并输出:
#include<iostream> using namespace std; int cirJudge(int n) { int sum = 0, w = 1, h = 0; int m,flag = 0; m = n; while (n) { h = n % 10; sum = sum * w + h; n = n / 10; w = 10; } if (sum == m) { flag = 1; } return flag; } int main() { int L,R; while (cin >> L >> R) { for (int i = L; i <= R; i++) { if (cirJudge(i)) { cout << i << " "; } } cout << endl; } return 0; }