Build a star tree
This would be a hard time when you just started coding.
But I would love to cheer you on because learning is a way of feeling Happiness.
This time I will make a startree you might have seen it before.
1. Make a left aligned Startree
for (int i = 0; i < 10; ++i)
{
for (int k = 0; k <= i; ++k)
{
Console.Write("*");
Console.Write(" ");
}
Console.WriteLine("");
}
This is the result of first code
you might want to align it to center don't you?
So i made it for you.
2. Make a center aligned Startree (with space)
for (int i = 0; i < 10; ++i)
{
for (int j = 10; j >= i; --j)
{
Console.Write(" ");
}
for (int k = 0; k <= i; ++k)
{
Console.Write("*");
Console.Write(" ");
}
Console.WriteLine("")
}
Result will be
3. Startree with no space
for (int i = 0; i < 10; ++i)
{
for (int j = 10; j >= i; --j)
{
Console.Write(" ");
}
for (int k = 0; k <= i; ++k)
{
Console.Write("*");
}
for (int k = 1; k <= i; ++k)
{
Console.Write("*");
}
Console.WriteLine("");
}
Result will be the tiny startree like this
728x90
최근댓글