Advertisement
brainuser5705

messy elasped time

Apr 25th, 2021
129
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<stdbool.h>
  3.  
  4. struct date{
  5.     int month;
  6.     int day;
  7.     int year;
  8. };
  9.  
  10. const char namesOfDay[7][3] =
  11. {{'S','U','N'},
  12. {'M','O','N'},
  13. {'T','U','E'},
  14. {'W','E','D'},
  15. {'T','H','U'},
  16. {'F','R','I'},
  17. {'S','A','T'}};
  18.  
  19. int main(void){
  20.     int getDifference(struct date, struct date);
  21.     int findNumDay(struct date);
  22.    
  23.     struct date firstDate = {8,3,2004};
  24.     struct date secondDate = {.month = 2, .day = 21, .year = 2005};
  25.     int diff = getDifference(firstDate, secondDate);
  26.  
  27.     printf("The difference between first date and second date is: %i\n", diff);
  28.  
  29.     int dayNum = findNumDay(secondDate);
  30.     printf("The day of first date is: %c%c%c", namesOfDay[dayNum][0], namesOfDay[dayNum][1], namesOfDay[dayNum][2]);
  31.  
  32.     return 0;
  33. }
  34.  
  35. int findNumDay(struct date date){
  36.     int findN(struct date);
  37.     return (findN(date) - 621049) % 7;
  38. }
  39.  
  40. int findN(struct date date){
  41.  
  42.     int f, g;
  43.     int specialDate(struct date);
  44.  
  45.     if (date.month <= 2){
  46.         f = date.year - 1;
  47.         g = date.month + 13;
  48.     }else{
  49.         f = date.year;
  50.         g = date.month + 1;
  51.     }
  52.  
  53.     return 1461 * f / 4 + 153 * g / 5 + date.day + specialDate(date);
  54. }
  55.  
  56. int getDifference(struct date firstDate, struct date secondDate){
  57.  
  58.     return findN(secondDate) - findN(firstDate);
  59.  
  60. }
  61.  
  62. int specialDate(struct date date){
  63.  
  64.     if (date.month >=2 && date.month <= 3){
  65.         if (date.year == 1800 || date.year == 1900)
  66.             return 1;
  67.         else if (date.year == 1700 || date.year == 1800)
  68.             return 2;
  69.     }
  70.  
  71.     return 0;
  72. }
Advertisement
RAW Paste Data Copied
Advertisement