I am not following this recursive function. Please help me code this to get the value of n as it hits each part before and after recursive call.
Code:
#include <stdio.h>
void puzzle(int n)
{
if (n != 0) {
printf("n = %d\n",n); /* want value of n passed to function */
printf("%d % 2 = %d\n",n,(n%2)); /* want value of n%2 to print out as n % 2 = "value" */
puzzle(n/2);
putchar('0' + n%2); /* prints out the valid output of function */
printf("\tn now = %d\n",(n%2)); /* prints out value of n after output of function */
}
}
main()
{
int i;
printf("input value \n");
scanf("%d",&i);
puzzle(i);
printf("\nValue after function call = %d",i); /* again prints out value of i which should be the original scanned input by user */
printf("\n\n");
return 0;
}