程序输入 我只安排了3个输入数据 但却需要输入4个数字才可以运行
#include<stdio.h>int day_of_year(int year, int month, int day)
{
int days;
int tab[2][12]={
{31,28,31,30,31,30,31,30,31,30,31,30},
{31,29,31,30,31,30,31,30,31,30,31,30}
};
int i;
int leap;
leap=(year%4==0&&year%100!=0)||year%400==0; //分辨是否为闰年
for(i=1;i<month;i++){
days+=tab[leap][i];
}
days+=day; //计算天数
return days;
}
int main()
{
while(1)
{
printf("Please enter the year-month-day:");
int year;
int month;
int day;
scanf("%d %d %d ",&year ,&month ,&day); //就是这里的问题,我只安排了3个输入,为什么要输入四次。
int days=day_of_year(year,month,day);
printf("The date %d_%d_%d is %d days.\n",year,month,day,days);
}
}