how many times will a function print to the console? [closed]
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
开发者_如何学Python Improve this questionI have the following snipet :
public class A
public A(int n)
{
for (int i=0; i<n; i++)
{
new A(i)
}
console.writeln("?")
}
for a given n - how many "?" will be printed ?
- some testing shows the answer is 2^n. What is the way to reach the formula?
- I got to the formula F(n) = 1 + F(n-1) +... +F(1) + 1
how do I simplify it to 2^n ?
If you cannot simplify it, perhaps you can prove it by induction.
http://en.wikipedia.org/wiki/Mathematical_induction
I don't know if this question is pertinent here... it has more to do with maths than with programming.
精彩评论