print palindrome in the range

#include <stdio.h>
void printpalindrome(int,int);
int main()
{
    int num,digit;
    scanf("%d%d",&num,&digit);
    printpalindrome(num,digit);
}
void printpalindrome(int num,int digit)
{
    int i,ds=1;
    for(i=1;i<=digit;i++)
    ds*=10;
    for(i=num;i<ds;i++)
    {
        int temp=i,rem;
        int rev=0;
        while(temp)
        {
            rem=temp%10;
            rev=(rev*10)+rem;
            temp=temp/10;
        }
        if(i==rev)
        printf("%d  ",i);
    }
}

input:
793 3
output:
797  808  818  828  838  848  858  868  878  888  898  909  919  929  939  949  959  969  979  989  999   

No comments:

Post a Comment