0
How Recursion works in C#
Help I don't understand how " return count += CountDivisions(number);" works in this code please enlighten me. class Program { public static int CountDivisions(double number) { int count = 0; if (number > 0 && number % 2 == 0) { count++; number /= 2; return count += CountDivisions(number); // specially this } return count; } static void Main(string[] args) { double number = 1000; Console.WriteLine("your number is {0}", number); int count = CountDivisions(number); Console.WriteLine(
quot;Total number of evenly divisions: {count}"); // the output is 3 } }3 Respostas
+ 2
C# Recursion tutorial
https://youtu.be/E7MMHAgxT5Q
+ 1
Thanks! But I don't know how " return count += CountDivisions(number);" works above code.
+ 1
Okay I got it, basically "return count += CountDivisions(number);" is to run the method again until it exits the condition if the "if statement" become false.