to solve questions of this type you must find a formula for spaces and a formula for stars. these formulas tell the computer how many spaces and stars must be printed in each line.
that’s all these types of questions need.
solved How to print the given ZIG ZAG pattern using C?