Quote:Original post by xMcBaiNx
I' sorry, you need to start counting the rows from 0 to n-1. So if there are 5 rows, they will be labeled 0 to 4. The absolute values takes care of the problem, see the example below for 5 rows.
spacesBeforeStarsRow1 = |(0 - (5-1)/2)| = 2
spacesBeforeStarsRow2 = |(1 - (5-1)/2)| = 1
spacesBeforeStarsRow3 = |(2 - (5-1)/2)| = 0
spacesBeforeStarsRow4 = |(3 - (5-1)/2)| = 1
spacesBeforeStarsRow5 = |(4 - (5-1)/2)| = 2
(Note that the loops have to start from 0 now.)
Sir, I've been saying that it would require four loops, one to move from 0 to N-1. Second to print spaces before Stars, third to print asteriks and fourth to print spaces after stars.
I was looking for an algorithm/pseudocode/hint-program to solve it in two loops.