计算天数——8-01.c 545 B

123456789101112131415161718192021222324252627
  1. #include <stdio.h>
  2. typedef struct {
  3. int year;
  4. int month;
  5. int day;
  6. } Date;
  7. int main() {
  8. Date date;
  9. scanf("%d %d %d", &date.year, &date.month, &date.day);
  10. int days_in_month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  11. if ((date.year % 4 == 0 && date.year % 100 != 0) || date.year % 400 == 0) {
  12. days_in_month[2] = 29;
  13. }
  14. int days = 0;
  15. int i;
  16. for ( i = 1; i < date.month; i++) {
  17. days += days_in_month[i];
  18. }
  19. days += date.day;
  20. printf("%d", days);
  21. return 0;
  22. }