Question: In C programming. How do you build a calendar? I can't get the days to work right. This is what I have so far #include
In C programming. How do you build a calendar? I can't get the days to work right.
This is what I have so far
#include
int dow(int year, int month, int day) { static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; year -= month < 3; return (year + year/4 - year/100 + year/400 + t[month-1] + day) % 7; }
int main() {
int year, month, day,daysM;
printf("Please input the year: "); scanf("%d",&year);
char *months[]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int monthDay[]={31,28,31,30,31,30,31,31,30,31,30,31};
if (year==-1){ printf("Error, no year specified "); return 1; } if (year < 1752) { printf("Error, year is earlier than 1752 "); return 1; }
if ((year + year/4 - year/100 + year/400 + day) % 7) { monthDay[1]=29; }
for (month=0; month<12; month++) { daysM=monthDay[month]; printf(" %s %d ",months[month],year); printf(" Sun Mon Tue Wed Thu Fri Sat ");
for(day=1;day
} }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
