Both the methods are good but the second one is judged on the basis of the output required. Though at the begineer level you need to focus on the output only but still if you divide the problem into parts then it would be easy to modify the same if more no. of star space rows are needed. if the no. of rows required changes all u have to do is to change digits in for loop.

So try to make generic programs to solve problems of a particular category and dont go for the solution to a particular problem. This will help you in future when you create programs for generating complex patterns. If for each such pattern you try to find a mathematical expressioned if startements than it will be creating problems for urself. So try to break a problem into parts and reach the conclusion.