← Coding round practice

Number Triangle

EasyPatterns

The problem

Print a triangle where each row i shows the numbers 1 to i.

Sample input

4

Sample output

1
1 2
1 2 3
1 2 3 4
Show the solution · 8 languages
fun main() {
    val n = 4
    for (i in 1..n) {
        println((1..i).joinToString(" "))
    }
}