Quote:
I know how I had to convert this in code but don't know the approach of question.
I understand the approach of the question in such a way that you should write a program that calculates the number of days after entering the data. What else could it mean? And because of the limited calculation, you would also have to limit the input of the year if the result is to match reality.
Based on OriginalGriff's suggestion, I briefly tested it on two examples.
date_t b_sam = { 22, 2, 1964 }; date_t d_sam = { 1, 8, 2032 };
unsigned myears = calcfullyears(b_sam, d_sam); unsigned bdaycnt = 0;
for (unsigned y = b_sam.y; y <= b_sam.y + myears; y++) {
if ((b_sam.m == 2) && (b_sam.d == 29) && (checkleap(y) == 0)) {
}
else {
mydow1 = dayofweek(y, b_sam.m, b_sam.d);
if (mydow1 == DMON) {
printf("Year %04u (on %s)\n", y, DAYNAM[mydow1]);
bdaycnt++;
}
}
}
with:
typedef struct {
unsigned d, m, y;
} date_t;
Birth: 1964 - 2 - 22 (on SAT)
Death : 2064 - 8 - 1 (on FRI)
Year 1965 (on MON)
Year 1971 (on MON)
Year 1982 (on MON)
Year 1988 (on MON)
Year 1993 (on MON)
Year 1999 (on MON)
Year 2010 (on MON)
Year 2016 (on MON)
Year 2021 (on MON)
Year 2027 (on MON)
Year 2038 (on MON)
Year 2044 (on MON)
Year 2049 (on MON)
Year 2055 (on MON)
Mr Sam had 14 birthdays on mondays, he lived 100 full years.
In fact, it is very bitter when the birthday falls on February 29th.
Birth: 1964 - 2 - 29 (on SAT)
Death : 2064 - 8 - 1 (on FRI)
Year 1988 (on MON)
Year 2016 (on MON)
Year 2044 (on MON)
Mr Sam had 3 birthdays on mondays, he lived 100 full years.
If you now knew how many full years Sam lived, you could roughly state it.
Between 1904 and 2096 there seems to be no exceptions in leap years, before and after that there is. In case of February 29th. there would be a lot less to count:
1904, ... ,1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036, ... 2096.
"Assume, the year which is divisible by 4 are leap years."
This assumption is correct at least for the leap years given above. Since the assumption is not always correct, incorrect days compared to the official calculation would be the result. The year range may have to be restricted.