C++ Program to Print Palindrome Numbers Between 1 to n using For Loop
Write C++ Program to Print Palindrome Numbers Between 1 to n using For Loop
// CPP Program to Print Palindrome Numbers Between 1 to n using For Loop #include <iostream> #include <stdbool.h> using namespace std; bool isPalindrome1(int n) { int temp = n, ans = 0; for(; n != 0; n = n / 10) { int remainder = n % 10; ans = ans * 10 + remainder; } if(temp != ans) { return false; } return true; } int main() { int n, i; cout << "Enter the number :--> "; cin >> n; cout << "Palindrome Numbers between 1 to " << n << " :--> "; for(i = 1; i < n; i++) { if(isPalindrome1(i)) { cout << i << " "; } } return 0; }
Output:
Enter the number :--> 25
The palindrome numbers are :1 2 3 4 5 6 7 8 9 11 22