Онлайн компилятор C

#include <stdio.h> void print_n_to_1(int n) { if (n == 1) { printf ("1"); return; } printf("%d",n); print_n_to_1(n - 1); return; } int main() { sum_to_n(5); printf("%d", sum_to_n(5)); return 0; }
这段代码定义了一个递归函数 `print_n_to_1`,它应该打印从 n 到 1 的数字,但主函数中却调用了未定义的 `sum_to_n` 函数,并且试图打印它的返回值。

- 主函数中调用了 `sum_to_n(5)`,但代码中并没有定义这个函数,只有 `print_n_to_1`。你需要确认到底想使用哪个函数。
- `print_n_to_1` 函数没有返回值,但主函数中试图用 `printf` 打印 `sum_to_n(5)` 的返回值,这会导致编译错误。如果希望打印结果,应该直接调用 `print_n_to_1` 函数。