Today i am going to execute a program which will create a right angled triangle. The right angled triangle will be created in the Julia console , we will use julia program to create a right angled triangle
function createTriangleUsingNumbers(numberOfRows)
for a=0:numberOfRows
for b=0:a
print(" ",b)
end
println(" ")
end
end
Result :
julia> createTriangleUsingNumbers(3)
0
0 1
0 1 2
0 1 2 3
julia> createTriangleUsingNumbers(8)
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8
julia> createTriangleUsingNumbers(11)
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10 11
Now we will see how to achieve it
function createTriangleUsingNumbers(numberOfRows)
for a=0:numberOfRows
for b=0:a
print(" ",b)
end
println(" ")
end
end
Result :
julia> createTriangleUsingNumbers(3)
0
0 1
0 1 2
0 1 2 3
julia> createTriangleUsingNumbers(8)
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8
julia> createTriangleUsingNumbers(11)
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
0 1 2 3 4 5 6
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 8
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9 10 11
Comments
Post a Comment