I have to perform a recursive procedure that prints this:
'\n' -----1 ----2 ---3 --4 -5
and for now I have this code that prints the numbers but not the "-" .
#include <stdio.h> // sprintf, scanf, ungetc, stdin
void recurrencia(int n) {
if (n > 0) {
recurrencia(n -1);
printf("%d\n", n);
} else printf("\n");
}
int main()
{
recurrencia(5);
return 0;
}
The problem is that I can't add a new parameter to the procedure and I can't use the variable n as a counter.
So my question is: How to record each time I recursively enter the same procedure so that I can add the amount of "-" corresponding to the "depth" with which I recursively entered?
If you can't change the recursion (Int n) procedure , but you can use a helper procedure, I would define one that keeps track of the number of recursions so I can print the '-' characters:
Departures: