#include int sum day(int(*)[13], int, int, int) days; int day tab[2[13}={{0,31,28,31,30,31,30,31,31,30,31,30,31} 0,31,29,31,30,31,30,31,31,30,31,30,31}/*记录每个月的天数* printf("请输入年、月、日(形如:198049):mn"), scanf("%d%d%d", &year, &month, &day ) days=sum day day tab, year, month, day) printf("这是该年的第%d天ln",days) int sum day (int('p)[13), int y, int m, int d /*指针变量p指向二维数组的一行* leap=y%4=0&&y%1001=0ly%400=0 体*如果为闰年,leap为1*/ d=*((p+leap)+i)
#include int sum_day(int(*)[13],int,int,int); void main() { int year,month,day,days; int day_tab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31}, {0,31,29,31,30,31,30,31,31,30,31,30,31}};/*记录每个月的天数*/ printf("请输入年、月、日(形如:1980 4 9):\n"); scanf("%d%d%d",&year,&month,&day); days=sum_day(day_tab,year,month,day); printf("这是该年的第%d 天\n",days); } int sum_day(int (*p)[13],int y,int m,int d) /*指针变量 p 指向二维数组的一行*/ { int i,leap=0; leap=y%4==0&&y%100!=0||y%400==0; /*如果为闰年,leap 为 1*/ for(i=1;i<m;i++) d+=*(*(p+leap)+i); return d; }