Hi,
I was asked to program a recursion (in C), which converts a binary to decimal.
The below code works well, yet I am not sure it fully exploits the potential of recursion (in particular the first two lines):
Iter and count are global variables set to 0 and 1 respectively.Code:int convert_bin_to_dec(int num) { iter++; if (iter != 1) count*=2; if (!(num / 10)) return (num * count); return ((num % 10) * count + convert_bin_to_dec(num /10)); }
I'd sincerely appreciate any feedback/suggestions.