写了个程序,请大家给指导指导,谢谢!
今天写课后题看到一个给你某年某月某日让你算是一年中的第几天,做完之后想试试如果给你一年中的第几天,你能不能算出是第几个月第几天,于是我用半个小时写下了一下这个代码,请大家给指导一下,有什么漏洞请尽可批评,谢谢大家!main()
{int year,day,i,j,month,month_tab[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
month=1;
printf("input year,day\n");
scanf("%d,%d",&year,&day);
printf("\n");
if(day<=31)
printf("Today is year %d month %d day %d \n",year,month,day);
else {if(((year%400==0)||(year%4&&year%100!=0))&&(day>=60))
day=day-1;
for(i=1;i<=12;i++)
{
day-=month_tab[i];
if(day<=28||day==30||day==31)
{month=i+1;
break;
}
}
printf("Today is year %d month %d day %d \n",year,month,day);
}
getch();
}