A colleague ask me to print a triangle (of any shape) using a single variable and in a single loop. I do it this way:
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Triangle
{
class Program
{
static void Main(string[] args)
{
var triangle = "*";
do { Console.WriteLine(triangle); }
while ((triangle += "*").Length < 10);
Console.ReadLine();
}
}
}
I hope there must be a better way of doing this. You know one?
EDIT:
Tim ask me how about print a triangle without using variable and loop. Ouch! I thought and still thinking :) you know how it can be done?