C Program to Print Palindrome Numbers Between n and m using For Loop

C Program to Print Palindrome Numbers Between n and m using For Loop

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

// C Program to Print Palindrome Numbers Between n and m using For Loop

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

bool isPalindrome1(int n)
{
	int temp = n, ans = 0;
	for(; n != 0; )
	{
		int remainder = n % 10;
		ans = ans * 10 + remainder;
		n = n / 10;
	}
	if(temp != ans)
	{
		return false;
	}

	return true;
}

int main()
{
	int n,m;
	printf("Enter n :--> ");
	scanf("%d", &n);

	printf("Enter m :--> ");
	scanf("%d", &m);

	printf("Palindrome Numbers Between %d to %d :--> ", n, m);

	int i = n ,j = m;
	for(; i < j; )
	{
		if(isPalindrome1(i))
		{
			printf("%d ",i);
		}
		i++;
	}

	return 0;
}

Output:

Enter n :--> 5
Enter m :--> 78
Palindrome Numbers Between 5 to 78 :--> 5 6 7 8 9 11 22 33 44 55 66 77