Answer the question
In order to leave comments, you need to log in
How to solve a problem in computer science?
You have to write out from the calendar the days of a certain month of a non-leap year, which fall on Sundays.
First, a number is entered (from 1 to 7), on which the first Sunday of January falls and the number of the month in which you need to select all Sundays,
explain at least in which direction to think
Answer the question
In order to leave comments, you need to log in
Days in a year continuous sequence 1-365. It's not a leap year, so February has 28 days.
Every month is an interval. January - from 1 to 31, February - from 32 to (31+28)...
1) First, enter the number (from 1 to 7) that falls on the first Sunday of January
This is the initial offset idx
2) Go by 7 from the initial offset (inclusive - January was suddenly set) idx = idx + 7.
3) If we fall into the interval of a given month, then subtract the beginning of the interval and get the date.
ps. In all formulas, you need to play around with + -1
, this is a head-on solution without libraries, there are options and faster.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question