learning-cc4e

Solution to https://cc4e.com/. If you copy these you're not right in the head.
git clone https://kaka.farm/~git/learning-cc4e
Log | Files | Refs

solution.c (536B)


      1 int day_of_year(pd) /* set day of year from month, day */
      2 struct simpledate *pd;
      3 {
      4   int i, day_number, leap;
      5 
      6   day_number = pd->day;
      7 
      8   leap = (
      9     (
     10       ((pd->year % 4) == 0)
     11       && ((pd->year % 100) != 0)
     12     )
     13     || ((pd->year % 400) == 0)
     14   );
     15 
     16   for (i = 1; i < pd->month; ++i) {
     17     day_number += day_tab[leap][i];
     18   }
     19 
     20   return day_number;
     21 }
     22 
     23 void dump_date(pd) /* print date from year, month, day */
     24 struct simpledate *pd;
     25 {
     26     printf("%d/%02d/%02d\n",
     27            pd->year,
     28            pd->month,
     29            pd->day);
     30 }