0
C# Level Points
The problem is "level points": levels as input. Complete the given function to take that number as an argument, and recursively calculate and return the total number of points given for all passed levels. The procedure was different. How was i supposed to use recursion? I did it like this: Main { int levels = Convert.ToInt32(Console.RL()); Console.WL(Points(levels));} static int Points(int levels, int points = 0){ for(int x = 0; x <=levels; x++){points += x;} return points;}
1 ответ
0
Hello,
So doing it recursively, you must call the subroutine itself, define the base case which is where 'levels' will be equal to 1 else we:
return levels + Points (levels-1)
Hope that helps