is my first time here so i dont know exactly how it works, so sorry for the mistakes.
What's the result from this function, when we give as "aktueller Parameter" the number 3?
(The original text:
Welches Ergebnis liefert diese Methode, wenn bei einem Aufruf als aktueller Parameter der Wert 3 übergeben wird?
Im studying in German, so i dont really know the english terms :/ )
public int m(int p)
{
int result;
if (p == 0)
{
result = 0;
}
else
{
result = 3*p + m(p-1);
}
return result;
}
I have already tried it and the answer is 18, but when im trying to do it without any program the answer i find is 15:
result = 3 * 3 + 3(3-1);
Can someone please explain me why is 18 and not 15? Im assuming that i am making something wrong.
Thank you in advance.
mandp. It's a recursive code, evaluates to3*3 + m(2), the second part becomes3*2 + m(1), andm(1) = 3, total is9+6+3 = 18.