程序在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 我要结婚祝福语简短
18 婚前女儿生日祝福语简短