Home

A program to find Palindrome numbers below given number

C Programming Language 030

The following code shows how to write a program to find Palindrome numbers below number 'n' and print them (NESTED DO WHILE).

Program

#include <stdio.h>

void main()
{
    int n, q, l, k = 1, rev = 0;

    printf("Enter a value: ");
    scanf("%d", &n);

    printf("Palindrome numbers below %d are:\n", n);

    do
    {
        q = k;
        rev = 0;
        do
        {
            l = q % 10;
            rev = l + 10 * rev;
            q = q / 10;
        } while (q > 0);

        if (rev == k)
        {
            printf("\t%d", k);
        }
        k++;
    } while (k <= n);

    printf("\n");
}

Result

Enter a value: 23
Palindrome numbers below 23 are:
        1       2       3       4       5       6       7       8       9       11      22


Last Updated on

Next Post: Rules vs Guidelines →

Comments