C Program to Print First n Palindrome Numbers 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; )
	{
		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("First %d Palindrome Numbers are :--> ", n);

	int count = 0;

	for(; count < n; )
	{
		if(isPalindrome1(i))
		{
			printf("%d ",i);
			count++;
		}
		i++;
	}

	return 0;
}

Output:

Enter the number :--> 15
First 15 Palindrome Numbers are :--> 1 2 3 4 5 6 7 8 9 11 22 33 44 55 66

≪ Previous | Next ≫