我给你写了一个
#include
#include
typedef struct _date
{
int year;
int month;
int day;
}date;
int dayofyear(int year,int month, int day);
int dayofyear_date(date d);
int getdaysofmonth(int year,int month);
int isleapyear(int year);
int main()
{
int count,index,year,month,day,*result;
date *pdate;
printf("输入你要判断的日期总数目");
scanf("%d",&count);
if(count > 0)
{
result = (int*)malloc(sizeof(int)*count);
pdate = (date*)malloc(sizeof(date)*count);
for(index = 0; index < count; ++index)
{
scanf("%d%d%d",&year,&month,&day);
*(result + index) = dayofyear(year,month,day);
(pdate + index)->year = year;
(pdate + index)->month = month;
(pdate + index)-> day = day;
}
for(index = 0; index < count; ++index)
{
printf("%d年%d月%d日\n",
(pdate + index)->year,
(pdate + index)->month,
(pdate + index)-> day);
}
for(index = 0; index < count; ++index)
{
printf("%d\n",*(result + index));
}
free(pdate);
free(result);
}
return 0;
}
int dayofyear(int year,int month, int day)
{
int i,days = 0;
for(i=1;i{
days += getdaysofmonth(year,i);
}
days += day;
return days;
}
int getdaysofmonth(int year,int month)
{
switch(year)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 4:
case 6:
case 9:
case 11:
return 30;
case 2:
if(isleapyear(year))
return 29;
return 28;
default:
return 0;
}
}
int isleapyear(int year)
{
return 0;
}
int dayofyear_date(date d)
{
return dayofyear(d.year,d.month,d.day);
}
没看出有什么问题。
不知道你为什么要把数组a定义为一个二维数组。
不管考虑不考虑闰年,二月都没有30天。