Consider the following function: int f (int num) { int out = 0; for (; num > 0; num /= 10) { int d = num % 10; out *= 10; out += d; } return out; } 1) What does it do? 2) Write the same algorithm using recursion
Anonymous
Sorry my answer previously posted was wrong. Here is the correct one without golbal or static variables, which is basically the same as the first one by Paul. inf f(int num, int car=0) { car *=10; if((num/10) == 0) return ( car + num ); else return f(num/10, car+(num%10) ); }
Check out your Company Bowl for anonymous work chats.