fork download
  1. #include <stdio.h>
  2.  
  3. #define COG1_TEETH 4
  4. #define COG2_TEETH 25
  5. #define COG3_TEETH 4
  6. #define BASE (4 * COG1_TEETH * COG2_TEETH * COG3_TEETH - 16)
  7.  
  8. int isleap(int year);
  9.  
  10. int main(void)
  11. {
  12. int year = 2100;
  13.  
  14. printf("%d is %s\n", year, isleap(year) ? "a leap year" : "not a leap year");
  15.  
  16. return 0;
  17. }
  18.  
  19. int isleap(int year)
  20. {
  21. unsigned a, b, c;
  22. unsigned i;
  23.  
  24. if (year < BASE) return 0; /* Not Gregorian year */
  25.  
  26. a = 0;
  27. b = COG2_TEETH - COG1_TEETH;
  28. c = COG3_TEETH - 1;
  29. i = year - BASE;
  30.  
  31. while (i--) {
  32. if (++a == COG1_TEETH) {
  33. a = 0;
  34. if (++b == COG2_TEETH) {
  35. b = 0;
  36. if (++c == COG3_TEETH)
  37. c = 0;
  38. }
  39. }
  40. }
  41.  
  42. return !b ? !a && !c : a == 0;
  43. }
  44.  
Success #stdin #stdout 0s 5244KB
stdin
Standard input is empty
stdout
2100 is not a leap year