C#的循环问题
如何用循环实现输出:1
2 3
4 5 6
7 8 9 10
int sum = 1; for (int i = 1; i <= 4; i++) { for (int j = 1; j <= i; j++) { Console.Write(sum.ToString()+" "); sum++; } Console.WriteLine(); }
int row = 1; int col = 0; for (int i = 1; i <= 10; i++) { Console.Write(i + " "); col++; if (row == col) { Console.WriteLine(); row++; col = 0; } }
Console.Write(Enumerable.Range(1, 150).Aggregate("", (s, i) => s + i + (Math.Sqrt(1 + 8 * i) % 2 == 1 ? "\n" : "\t")));