Ok i will bite
So, the goal is to print a triangle of stars. Well, we need some kind of loop, perhaps with a different inner loop. And we know that it will be symmetrical because it is a triangle.
so I would start by printing the first half:
function triangle( input ) i <- 1 while i < input do for j from 1 to i do print "*" end for i <- i + 2 print "\n" end while
After that, we will need to deal with the second half of the triangle, which, since we have already reached the input value, means that we can simply return to it.
if i > input then i <- i - 2 while i > 0 do for j from 1 to i do print "*" end for i <- i - 2 print "\n" end while end function triangle
The little trick in it that almost caught me is subtracting two to the second, and if you don't, you will get the wrong answer. Iβll leave to understand why itβs up to you. If the pseudo-code entry is confused, please ask.
zellio
source share