First of all, you need to analyze the problem.
The spiral of 9 includes the spiral of 5, which include the spiral of 1.
One can guess it will continue with 13, 17, 21, 25 ...
You can't use specific handling for every spiral sizes, you have to find another way.
In this case, the easiest is using a 2d array that you will use like a sheet of paper.
Put the pencil at starting point and draw first line, then second and so on.
You only have to handle how second you draw the second loop in reduced square.
Think how it will translate to code.