可以使用数组,并且使用数组代码更简洁一些,参考代码如下:
#include <stdio.h>
int main()
{
int i, days = 0;
int year, month, day;
int day_tab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf("输入年、月、日,用空格隔开:");
scanf("%d%d%d", &year, &month, &day);
for (i=1; i<month; i++)
{
days += day_tab[i];
}
days += day;
if ((year%4==0 && year%100!=0 || year%400==0) && month>=3)
days+=1;
printf("%d年%d月%d日是这一年的第%d天! ", year, month, day, days);
return 0;
}