/* debug_this.c Jeff Ondich, 27 March 2023 A simple program for use with our VS Code debugging lab. Yes, this program includes an error. */ #include #include int iterative_triangular_number(int n); int recursive_triangular_number(int n); int main(int argc, char *argv[]) { int limit = 10; printf("Here are the first %d triangular numbers, recursively computed:\n", limit); for (int k = 1; k <= limit; k++) { int t = recursive_triangular_number(k); printf(" T(%d) = %d\n", k, t); } printf("\n"); printf("Here are the first %d triangular numbers, iteratively computed:\n", limit); for (int k = 1; k <= limit; k++) { int t = iterative_triangular_number(k); printf(" T(%d) = %d\n", k, t); } printf("\n"); return 0; } // Returns the nth triangular number, or 0 if n <= 0. // The nth triangular number is the sum of the first // n positive integers. For example, triangular_number(3) // is equal to 1 + 2 + 3 = 6. int iterative_triangular_number(int n) { int total = 0; for (int k = 0; k < n; k++) { total = total + k; } return total; } // Same, but recursive. int recursive_triangular_number(int n) { if (n < 1) { return 0; } int t = recursive_triangular_number(n - 1); t = t + n; return t; }