运用结构体
for (k = 1990; k < DATE.year; k++) {
if ((k % 4 == 0 && k % 100 != 0) || k % 400 == 0)
j = j + 1;
}//如果平年,365天,是5的倍数,除5后为0;
//如果闰年,366天,比5倍数多1,除5后为1
#include <stdio.h> struct date { int year, month, day; } DATE; int main() { int i = 0, j = 0, k; int a[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 }; printf("Enter year/month/day:"); scanf("%d%d%d", &DATE.year, &DATE.month, &DATE.day); for (k = 1990; k < DATE.year; k++) { if ((k % 4 == 0 && k % 100 != 0) || k % 400 == 0) j = j + 1; } for (i = 1; i < DATE.month; i++) { j += a[i]; } if (((DATE.year % 4 == 0 && DATE.year % 100 != 0) || DATE.year % 400 == 0) && DATE.month > 2) j += 1 + DATE.day; j = j % 5; if (j <= 3) printf("He is fishing.\n"); else printf("He is sleeping.\n"); }