Sunday, December 21, 2014

Replace all ‘0’ with ‘5’ in an input Integer

 /* Use of array to store all digits is not allowed.*/
#include<stdio.h>
static int x=0;
int fun(int num)
{
    if(num==0)
    {
    return;
    }
    else
    {
    int rem=num%10;
    if(rem==0)
    {
     rem=5;
    }
    num=num/10;
    fun(num);
    x=x*10+rem;
    }
return x;
}
int main()
{
printf("num is %d ",fun(105));
return 0;
}