Startree C#

이것저것 / / 2021. 5. 20. 01:06

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
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기