Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdbool.h>
- struct date{
- int month;
- int day;
- int year;
- };
- const char namesOfDay[7][3] =
- {{'S','U','N'},
- {'M','O','N'},
- {'T','U','E'},
- {'W','E','D'},
- {'T','H','U'},
- {'F','R','I'},
- {'S','A','T'}};
- int main(void){
- int getDifference(struct date, struct date);
- int findNumDay(struct date);
- struct date firstDate = {8,3,2004};
- struct date secondDate = {.month = 2, .day = 21, .year = 2005};
- int diff = getDifference(firstDate, secondDate);
- printf("The difference between first date and second date is: %i\n", diff);
- int dayNum = findNumDay(secondDate);
- printf("The day of first date is: %c%c%c", namesOfDay[dayNum][0], namesOfDay[dayNum][1], namesOfDay[dayNum][2]);
- return 0;
- }
- int findNumDay(struct date date){
- int findN(struct date);
- return (findN(date) - 621049) % 7;
- }
- int findN(struct date date){
- int f, g;
- int specialDate(struct date);
- if (date.month <= 2){
- f = date.year - 1;
- g = date.month + 13;
- }else{
- f = date.year;
- g = date.month + 1;
- }
- return 1461 * f / 4 + 153 * g / 5 + date.day + specialDate(date);
- }
- int getDifference(struct date firstDate, struct date secondDate){
- return findN(secondDate) - findN(firstDate);
- }
- int specialDate(struct date date){
- if (date.month >=2 && date.month <= 3){
- if (date.year == 1800 || date.year == 1900)
- return 1;
- else if (date.year == 1700 || date.year == 1800)
- return 2;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement