My question is how to make a pyramid using * and \'space\' in C#? The output will be like this.
*
* *
* * *
* * * *
* * * * *
<
Post my answer after 3 hours. I think now you have almost finished it under @iluxa's advice?
int height = 20;
for (int level = 1; level <= height; level++)
{
string text = string.Join(" ", Enumerable.Repeat("*", level));
Console.WriteLine(text.PadLeft(height - level + text.Length));
}
I used some build-in methods e.g. Enumerable.Repeat
and String.PadLeft
, not the pure C-language way. The purpose is that I want to tell you since you have chosen C# as the programming language(not C/Java/etc), you should resolve problems in the C# way.