Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #define MAX_STRING_LENGTH 50
- #define MAX_WEEKDAYS 7
- char week_days[MAX_WEEKDAYS][MAX_STRING_LENGTH] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
- int main(void){
- int year;
- printf("Enter year between 0 and 2019:\n> ");
- do{
- scanf("%d", &year);
- if(year < 0 || year > 2019){
- printf("Wrong input! Try again.\n> ");
- }
- } while(year < 0 || year > 2019);
- /* number of days in given year */
- bool leap_year;
- if (year % 400 == 0){
- leap_year = true;
- } else if (year % 100 == 0){
- leap_year = false;
- } else if (year % 4 == 0){
- leap_year = true;
- } else{
- leap_year = false;
- }
- /* 1.1.#### */
- int d = 1;
- int m = 1;
- int y = year;
- /* 0 -> Sunday, 1 -> Monday, 2 -> Tuesday, 3 -> Wednesday, 4 -> Thursday, 5 -> Friday, 6 -> Sunday */
- int first_of_january = (d += m < 3 ? y-- : y - 2, 23 * m / 9 + d + 4 + y / 4 - y / 100 + y / 400) % 7;
- printf("\nMost days in year %d: ", year);
- /* non-leap year = 365 days -> most days: day on the 1st of January */
- if(!leap_year){
- printf("%s\n", week_days[first_of_january]);
- /* leap year = 366 days -> most days: day on the 1st of January and the day after */
- } else{
- printf("%s and %s\n", week_days[first_of_january], week_days[(first_of_january + 1) % 7]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement