程序在C ++中打印给定范围内的所有回文
在本教程中,我们将讨论在给定范围内打印所有回文的程序。
为此,我们将给出找到回文的数学范围。我们的任务是找到该范围内的所有回文并打印回去。
示例
#include<iostream>
using namespace std;
//checking if the number is a palindrome
int is_palin(int n){
int rev = 0;
for (int i = n; i > 0; i /= 10)
rev = rev*10 + i%10;
return (n==rev);
}
void countPal(int min, int max){
for (int i = min; i <= max; i++)
if (is_palin(i))
cout << i << " ";
}
int main(){
countPal(99, 250);
return 0;
}输出结果
99 101 111 121 131 141 151 161 171 181 191 202 212 222 232 242
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短