Cześć wszystkim, próbuję zrozumieć rekurencję poprzez rozwiązanie tego przykładu:
namespace ConsoleApp25
{
class Program
{
//W = (x+1) + (x+2) + (x+3) +.......+ (x+n).
static int Rekurencja(int x, int n)
{
if (x == 0)
return 1;
return x + Rekurencja(x - 1, n);
}
static void Main(string[] args)
{
Console.Write("Podaj x: ");
int x = int.Parse(Console.ReadLine());
Console.Write("Podaj n: ");
int n = int.Parse(Console.ReadLine());
Console.WriteLine(Rekurencja(x, n));
}
}
}
Niestety robię to źle i nie wiem jak poprawić ten kod, aby rekurencja była użyta poprawnie.
99xmarcin