I'm stuck with a recursive exercise in C #, then I leave the slogan:
-Make a tree as detailed below from the entry of a value of a variable.
Ex: Entry 5
- - - - 1
- - - 2 2 2
- - 3 3 3 3 3
- 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
(I do not know if it looks good, but the idea is to be in the form of triangular pine)
If someone could give me a hand to solve it, I would appreciate a lot, I think there is something in the statement that I am not able to reason.
The code I could reach is the following:
class Program
{
public class Arbol
{
void hacerArbol(int x)
{
if (x > 0)
{
hacerArbol(x - 1);
if (x < 5)
{
Console.Write("_" + " ");
}
else
{
Console.Write(x);
Console.WriteLine();
}
//hacerArbol(x - 1);
}
}
static void Main(string[] args)
{
Arbol nuevo = new Arbol();
nuevo.hacerArbol(5);
Console.ReadKey();
}
}
}
I can not manage to pose the figure that is asked, I think there is a part that I can not imagine how to do.