Do you need to know this for a certain year? Or is it just this year? If you need to know this for any year, you can list "days per month", having one for leap years and one for off-peak years.
You just need to know what day of the week the year began (i.e., Monday, Tuesday, etc.)
You will have at least 5 dates for any month, so you can have an array with a fixed int length.
You know that the gregorian calendar is repeated every 400 years, and that if year X started on day βYβ, then year X + 1 will start with day (βYβ + 1)% 7, if x is not a leap year, if it is a leap year, it will start on the day ("Y" + 2). which can give you the first date of any year, and knowing how many days you have all the months for any year, you can easily get the date on which this month begins ("Monday", etc.).
Then all you have to do is something like
int offset = 0; int i; while (myDate + offset != monthStartingDate) { offset++; } i = offset + monthStartingDate;
(myDate is the day of the week, and monthStartingDate is the day of the week on the first day of this month)
when you exit this cycle, you will have the first occurrence, then you simply add 7 until I go beyond the month.
you can add each i to the array.
int res[5] = {0,0,0,0,0} for ( ; i < daysOfMonth(month, year); i += 7) { int res[i / 7] = i; }
then you just return res.
Oh, I donβt know that you could use date functions: P I think the idea of ββthe exercise was fulfilling C: P