namespace summary { internal class Program { static void Main(string[] args) { //1. lehetőség Console.WriteLine("Give me a natural numner n: "); ulong x = ulong.Parse(Console.ReadLine()); Console.WriteLine("The sum of the first {0} number is: {1} (iterative version)", x, sum1(x)); Console.WriteLine(); Console.WriteLine("The sum of the first {0} number is: {1} (rucursive version)", x, sum2(x)); Console.WriteLine(); Console.WriteLine("The sum of the first {0} number is: {1} (rucursive version)", x, sum3(1,x)); Console.WriteLine(); double y = sum4(x); Console.WriteLine("The sum of (1/i^2), where i=1..{0} number is: {1} (rucursive version)", x, y); Console.WriteLine(); Console.WriteLine(Math.Sqrt(6*y)); Console.ReadLine(); } public static ulong sum1(ulong n) { ulong s = 0; for (ulong i = 1; i < n + 1; i++) { s += i; } return s; } public static ulong sum2(ulong n) { ulong s; if (n == 1) { s = 1; } else { s = n + sum2(n - 1); } return s; } public static ulong sum3(ulong n, ulong m) { ulong s; if (n == m) { s = n; } else { ulong k = (n + m) / 2; s = sum3(n,k) + sum3(k+1,m); } return s; } public static double sum4(ulong n) { double s; if (n == 1) { s = 1; } else { s = Math.Pow((double) 1 /n,2) + sum4(n - 1); } return s; } } }