看看这个是不是你要的啊
#include<stdio.h>
char daytab[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},
};
int day_of_year(int year,int month,int day)
{
int i,leap;
leap = year % 4 == 0 && year % 100 != 0 || year % 400 ==0;
for(i = 1; i < month; i++)
day += daytab[leap][i];
return day;
}
int get_year_day(int *year,int *month,int *day)
{
int leap;
printf("输入年月日\n");
scanf("%d%d%d",year,month,day);
leap = *year % 4 == 0 && *year % 100 != 0 || *year % 400 ==0;
if(*month < 1 || *month >12)
{
printf("请重新输入\n");
return 0;
}
else if(*day < 1 || *day > daytab[leap][*month])
{
printf("请重新输入\n");
return 0;
}
else
return 1;
}
int main(void)
{
int year,month,day;
int sign,days;
days = 0;
sign = 0;
while(!sign)
{
sign = get_year_day(&year,&month,&day);
}
days = day_of_year(year,month,day);
printf("the %d年%d月%d日 is the %d days of years\n",year,month,day,days);
return 0;
}