[原创]百思不解的问题????????????
这个是输入年月日求这一年中第几天的程序,怎么输入2月以后的月份,总的天数多了一天????????????
#include"stdio.h"
main()
{
int days[2][12]={
{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}
};
int year,month,i,day1,day2,sum=0;
int leap;
printf("qing shu ru nian yue ri\n");
scanf("%d,%d,%d",&year,&month,&day1);
if((year%4==0&&year%100!=0)||(year%400==0))/*润年判断
leap=1;
else
leap=0;
day2=days[leap][month-1];
if(day1>day2) /****日期合法判断
printf("shu ru you cuo!\n");
else
{
if(month==1) /*1月份的天数
{sum=day1;
printf("%dnian,%dyue,%dri shi di %d tian\n",year,month,day1,sum);}
else
{
for(i=0;i<month-1;++i) /*判断2月以后的天数
sum=sum+days[leap][i];
printf("%d\n",sum);
sum=sum+day1; /*可能是这里出错 有谁能告诉我 为什么??
printf("%dnian,%dyue,%dri shi di %d tian\n",year,month,day1,sum);
}
}
}