It's not complicated.
Decide on your start-of-week day:
S M T W T F S
Or
M T W T F S S
For example.
Then, work out the day of week for the 1st of the month.
You want to space entries until you get to there:
S M T W T F S
1 2 3 4 5
...
Then just start printing increasing numbers in groups of 7.
If you stop and think about it, and break it down into smaller tasks each time, it's pretty simple.