To print leading space and zero, you can use this:
int x = 119, width = 5;
printf("%*d\n",width,x);
printf("%0*d\n",width,x);
So, in your program, just change this:
int i, digit, width=5, x=15;
if(x%2==0)
printf("%*d\n",width,x);
else
printf("%0*d\n",width,x);
source
share