使用 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
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP