Created
March 30, 2020 08:45
-
-
Save raikusy/72938d7a5faebd03c19ba5f8b9ad7672 to your computer and use it in GitHub Desktop.
Calender C Program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int get_starter(int year) { | |
int day = (((year - 1) * 365) + ((year - 1) / 4) - ((year - 1) / 100) + ((year) / 400) + 1) % 7; | |
return day; | |
} | |
int main() { | |
int year, month, date, dayinM, dayinW = 0, starter; | |
printf("\n ENTER 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 % 4 == 0 && year % 100 != 0) || year % 400 == 0) | |
monthDay[1] = 29; | |
starter = get_starter(year); | |
for (month = 0; month < 12; month++) { | |
dayinM = monthDay[month];; | |
printf("\n\n____________________%s____________________\n", months[month]); | |
printf("\n SUN MON TUE WED THU FRI SAT\n"); | |
for (dayinW = 0; dayinW < starter; dayinW++) | |
printf(" "); | |
for (date = 1; date <= dayinM; date++) { | |
printf("%6d", date); | |
if (++dayinW > 6) { | |
printf("\n"); | |
dayinW = 0; | |
} | |
} | |
starter = dayinW; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment