- To print half triangle pattern using number
User Input: 3
Output:
1 1 2 1 2 3
fun main(args: Array<String>) {
print("Enter number of rows : ")
val userInput = readLine()!!
var rows:Int =userInput.toInt()
for(i in 1..rows) {
for(j in 1..i) {
print(j +" ")
}
println("")
}
}
Enter number of rows : 4 1 1 2 1 2 3 1 2 3 4Program
Main logic :
for(i in 1..rows) { //rows : number of rows to print
for(j in 1..i) {
print(j +" ")
}
println("")
}
Concept
Coming Soon !
QuickIn order to succeed you must fail, so that you know what not to do the next time.