namespace ALGA { public class PyramidProblem { public static int triangular_number_recursive(int n) { if (n <= 0) return 0; return n + triangular_number_recursive(n - 1); } public static int triangular_number_iterative(int n) { if (n <= 0) return 0; int total = 0; for (int i = 1; i <= n; i++) total += i; return total; } public static int triangular_number_function(int n) { if (n <= 0) return 0; return (n + 1) * n / 2; } } }