我来说几句
程序段中输入部分“scanf("%d",&date1.day);”好像没什么用,反而影响结果,把这一行删掉后就可以运行了。
在输入时年月日时,也只需用逗号间隔。另外,补充一点,四年一闰,搂主程序中的“if” ,“else”条件判断需要交换一下
改正后程序为:
#include"stdio.h"
int main()
{
int a,i=0,yearday;
struct
{
int year;
int month;
int day;
}date1;
static int month[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}};
printf("please input the year month and day:\n");
scanf("%d,%d,%d",&date1.year,&date1.month,&date1.day);
a=date1.month;
yearday=date1.day;
if((date1.year%4==0&&date1.year%100!=0)||(date1.year%400==0))
{
for(i=0;i<a;i++)
yearday+=month[1][i];
}
else
{
for(i=0;i<a;i++)
yearday+=month[0][i];
}
printf("the yearday is %d\n",yearday);
}
[此贴子已经被作者于2007-8-28 11:31:40编辑过]