In today's program we will see how to create a right angled triangle. To create a triangle program we will create a method by name createTriangle and pass a parameter, by passing the parameter we can reuse the method as many number of times with different rows. Here we will use Asterisk to print the triangle on the screen .
Here goes our triangle which will look like this
To create the above triangle, we will see how to write the program
function createTriangle(numberOfRows)
for a=0:numberOfRows
for b=0:a
print("* ")
end
println(" ")
end
end
Output : For right angled triangle program
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
Here goes our triangle which will look like this
To create the above triangle, we will see how to write the program
function createTriangle(numberOfRows)
for a=0:numberOfRows
for b=0:a
print("* ")
end
println(" ")
end
end
Output : For right angled triangle program
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
Comments
Post a Comment