我还以为运行不起来了,吓死我了
程序代码:
#include<stdio.h> struct Date { int year; int month; int day; }; int day_sum(struct Date a) { int day_tab[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 }; int sum = 0; int i; for (i = 0; i < a.month; i++) sum += day_tab[i]; sum += a.day; if (((a.year % 4 == 0 && a.year % 100 != 0) || a.year % 400 == 0) && a.month > 2) sum += 1; return sum; } int main() { int day_sum(struct Date a); struct Date a; int days; printf("Input year,month and day:\n"); scanf_s("%d%d%d", &a.year, &a.month, &a.day); days = day_sum(a); printf("%d/%d is the %dth day in %d\n", a.month, a.day, days, a.year); return 0; }