Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Вывести все палиндромы на отрезке*/
- #include <iostream>
- using namespace std;
- bool isPalindrome(int cur)
- {
- int base = cur;
- int rev = 0;
- while (cur)
- {
- rev = rev * 10 + cur % 10;
- cur /= 10;
- }
- if (base == rev)
- return true;
- else
- return false;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- cout << "Введите n: ";
- int n;
- cin >> n;
- int cur = 2;
- cout << "Все числа-полиндромы на отрезке [2," << n << "]: ";
- while (cur <= n)
- {
- if (isPalindrome(cur))
- cout << " " << cur;
- cur++;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment