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