Navigation

Saturday, 28 February 2015

Reverse input number using Recursion

int revint(int);
void main()
{
    int n,result;
    clrscr();
    printf("Enter the number::=>");
    scanf("%d",&n);
    result=revint(n);
    printf("The reverse of number %d is %d",n,result);
    getch();
}
int revint(int p)
{
    int d;
    static int r=0;
    if(p==0)
    {
        return(p);
    }
    else
    {
        d=p%10;
        r=r*10+d;
        revint(p/10);
    }
    return(r);
}

No comments:

Post a Comment