Printing an ascending asterisk triangle

Report a typo

Write a program that reads a positive integer N and prints a triangle with N rows using asterisks ('*'). Each row should have one more asterisk than the previous row, starting with one asterisk in the first row.

Sample Input 1:

5

Sample Output 1:

*
**
***
****
*****

Sample Input 2:

3

Sample Output 2:

*
**
***
Write a program in Kotlin
// Import for reading user input
import java.util.Scanner

fun main() {
val scanner = Scanner(System.`in`)

// Read the positive integer N
val n = scanner.nextInt()

// TODO: Print a triangle with N rows using asterisks ('*')
// - Each row should have one more asterisk than the previous row
// - Start with one asterisk in the first row
repeat(n) {
// Your code here
}
}

Create a free account to access the full topic