C Program to Print First n Palindrome Numbers using While loop

C Program to Print First n Palindrome Numbers using While loop

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

	int count = 0;

	while(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