C Programming Problem: Given the year and day number of that year on which the f
ID: 3598176 • Letter: C
Question
C Programming
Problem: Given the year and day number of that year on which the fall semester begins, determine the calendar date of the start of the semester, when October Break will take place, and when the Thanksgiving Break will occur. The starting date must be a Monday (see example #5), October Break is always during Monday and Tuesday of the 8th week of the semester, and Thanksgiving will take place on the fourth Thursday in November with the day before and after being a part of the break Several formulas necessary for this problem can be found on page 300 of your C programming text. Example Execution #1: Enter the year 2017 Enter the day number on which the fall semester begins: 233 Semester start date: 08/21/2017 October Break 2017: 10/09 -10/10 Thanksgiving Break 2017 11/22 - 11/24 Example Execution #2: Enter the year 2018 Enter the day number on which the fall semester begins: 232 Semester start date: 08/20/2018 October Break 2018: 10/08 10/09 Thanksgiving Break 2018 11/21 - 11/23 Example Execution #3: Enter the year: 2019 Enter the day number on which the fall semester begins: 231 Semester start date: 08/19/2019 October Break 2019: 10/07- 10/08 Thanksgiving Break 2019 11/27-11/29 Example Execution #4 (leap year): Enter the year: 2020 Enter the day number on which the fall semester begins: 237 Semester start date: 08/24/2020 October Break 2020: 10/12 - 10/13 Thanksgiving Break 2020 11/25 11/27 Example Execution #5: Enter the year 2017 Enter the day number on which the fall semester begins: 235 The date: 08/23/2017 does not fall on a Monday.Explanation / Answer
#include<stdio.h>
int main() {
int dn=0;
long int dt = 0 ;
int d=0;
int m=8;
long y=0;
int lt=0 ;
int jd=212;
int od=0;
int td=0;
printf("Enter the year: ");
scanf("%d",&y);
printf(" Enter the day number on which the fall semester begins: ");
scanf("%d",&dn);
dt = ((long)(y-1)*365+(long)((y-1)/4)-(long)((y-1)/100)+(long)((y-1)/400))%7;// 31st of previous year
dt += dn ;
dt %= 7 ;
if((!(y%4)&&(y%100))||!(y%400))
{
jd++;// Increase by 1 if leap year
}
dn -= jd;// decrease till july
if(dt!=1)
{
printf(" The date: %d/%d/%d does not fall on a Monday.", m,dn,y); // If not Monday invalid input
}
else
{
printf(" Semester start date: %d/%d/%d ", m,dn,y);
dn += (49-31-30); // Reach Monday of 8th week
printf(" October break %d: 10/%d - 10/%d ",y, dn,(dn+1));
jd += 113 ; // Complete three weeks till november
dt = ((long)(y-1)*365+(long)((y-1)/4)-(long)((y-1)/100)+(long)((y-1)/400))%7;// 31st of previous year
dt += jd ;
dt %= 7 ;
dn = 21 ;
if(dt<=3)
dn += (3-dt);
else if(dt>3)
dn += (10-dt);
printf(" Thanksgiving break %d: 11/%d - 11/%d ",y, dn,(dn+2));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.