01.#include<stdio.h> 02.int main() 03.{ 04. int count(int month); 05. int year,month,day;//定义年月日 06. int i,leap,sum=0;//定义变化量 07. printf("please input the date (eg:2010-01-01):"); 08. scanf("%d-%d-%d",&year,&month,&day); 09. //判断是否为闰年 10. if(year%400==0||year%4==0&&year%100!=0) 11. leap=1; 12. else 13. leap=0; 14. //计算month之前共有多少天 15. for(i=1;i<month;i++) 16. { 17. sum=sum+count(i); 18. } 19. //如果月份大于2,要考虑是否为闰年! 20. if(month>2) 21. printf("the day is %dth day of %d/n",sum+day+leap,year); 22. else 23. printf("the day is %dth day of %d/n",sum+day,year); 24. return 0; 25.} 26.int count(int month) 27.{ 28. //判断每个月有多少天,被主函数调用 29. int days; 30. switch(month) 31. { 32. case 1: 33. case 3: 34. case 5: 35. case 7: 36. case 8: 37. case 10: 38. case 12: days=31;break; 39. case 4: 40. case 6: 41. case 9: 42. case 11: days=30;break; 43. case 2:days=28;break; 44. } 45. return (days); 46.} 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/iindus/archive/2010/07/20/5748016.aspx