楼上的算法有漏洞.
最后一步如果是润年,天数加一出错了.
假设是闰年,但是给的日期没有超过2.29,那就不需要加一.这步没考虑
#include "stdio.h"
main ()
{
int year, month, day;
int total;
int leap;
printf ("enter year.month.day\n");
scanf ("%d.%d.%d.", &year, &month, &day);
switch (month)
{
case 1: total=0+day; break;
case 2: total=31+day; break;
case 3: total=59+day; break;
case 4: total=90+day; break;
case 5: total=120+day; break;
case 6: total=151+day; break;
case 7: total=181+day; break;
case 8: total=212+day; break;
case 9: total=243+day; break;
case 10: total=273+day; break;
case 11: total=304+day; break;
case 12: total=334+day; break;
}
leap=year%4==0&&year%100!=0||year%400==0;
if (leap&&month>2)
total++;
printf ("%d", total);
getch ();