To write it horizontally, you'll need to store the values somewhere as you populate each line up to n. One option is storing it in an array.
For each triangle, you need to first fill it with + symbols, and then fill the remaining with .
So for input 5, you would have 5 triangles, each one going from 1 triangle on the first line, 2 triangles on the second line, all the way up to 5 triangles on the fifth line. Once you're done with looping, you should end up with something like this in your array for the first triangle.
var example = new string[] {
"+ "
,"++ "
,"+++ "
,"++++ "
,"+++++"
};
For the second triangle, you would add a space and then extend the existing strings so they become longer.
var example = new string[] {
"+ + "
,"++ ++ "
,"+++ +++ "
,"++++ ++++ "
,"+++++ +++++"
};
And so on and so on up the n-th triangle.
Here's the example code.
Console.WriteLine("Enter the number of triangles: ");
int n = int.Parse(Console.ReadLine());
var lines = new string[n + 1];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n + 1; j++)
{
// populate from 0 to j with "+" characters
for (int k = 0; k < j; k++)
lines[j] += "+";
// populate from j to n + 1 with " " characters
for (int k = j; k < n + 1; k++)
lines[j] += " ";
}
}
// skip the first row
for (int i = 1; i < n + 1; i++)
Console.WriteLine(lines[i]);
Here's what the output looks like:
Enter the number of triangles:
5
+ + + + +
++ ++ ++ ++ ++
+++ +++ +++ +++ +++
++++ ++++ ++++ ++++ ++++
+++++ +++++ +++++ +++++ +++++