#include <stdio.h>
void month_day ( int year, int yearday, int * pmonth, int * pday)
{
int k, leap;
int 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 }, //闰年
};
// 建立闰年判别条件leap
leap = (year%4 == 0 && year%100 != 0) || year%400 == 0;
for ( k = 1; yearday > tab[leap][k]; k++)
yearday -= tab [leap][k];
*pmonth = k;
*pday = yearday;
}
int main (void)
{
int day, month, year, yearday;
void month_day(int year,int yearday, int *pmonth,int *pday);
printf("Input year and yearday:\n");
scanf ("%d %d", &year, &yearday );
month_day (year, yearday, &month, &day );
printf ("%d-%d-%d \n", year, month, day );
return 0;
}
明白leap是判断是否为闰年,如果不等于0会怎么运行呢没太理解这个
可不可以写成,if 它等于0,else等于1?