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
//Write a C program to Print Palindrome Numbers Between 1 to n using While Loop #include <stdio.h> #include <stdbool.h> 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; printf("Enter the number :--> "); scanf("%d", &n); int i = 1 ; printf("Palindrome Numbers between 1 to %d :--> ", n); while(i < n) { if(isPalindrome1(i)) { printf("%d ",i); } i++; } return 0; }
Output:
Enter the number :--> 25
The palindrome numbers are :1 2 3 4 5 6 7 8 9 11 22