C Program to Print Palindrome Numbers Between 1 to n using For Loop

C Program to Print Palindrome Numbers Between 1 to n using For Loop

Write a Program to Print Palindrome Numbers Between 1 to n using For Loop

// C program to Print Palindrome Numbers Between 1 to n using For Loop

#include <stdio.h>
#include <stdbool.h>

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;

	printf("Enter the number :--> ");
	scanf("%d", &n);

	printf("Palindrome Numbers between 1 to %d :--> ", n);
	for(i = 1; i < n; i++)
	{
		if(isPalindrome1(i))
		{
			printf("%d ",i);
		}
	}

	return 0;
}

Output:

Enter the number :--> 25
The palindrome numbers are :1 2 3 4 5 6 7 8 9 11 22