用C语言来实现_输入一个日期(年月日),计算是这一年中的第几天(集思广议)

用C语言来实现_输入一个日期(年月日),计算是这一年中的第几天(集思广议)

2017年11月05日 18:18:12 shengDay 阅读数:496更多
个人分类: C&C++编程

用C语言来实现_输入一个日期(年月日),计算是这一年中的第几天http://blog.csdn.net/wxwd521/article/details/7852230

1.环境:
2.代码:
/*
*wuxiuwen
*input date, the date of this year is calculated which day.
*输入一个日期(年月日),计算是这一年中的第几天
*/
#include

int dm(int year,int month, int day)
{
int flag=0;
if((year%40 && year%100!=0) || (year%400100))flag = 1;//此法很妙
else flag =0;//此法很妙
int a=0;
switch(month-1)
{
case 11 :a+=30;
case 10 :a+=31;
case 9 :a+=30;
case 8 :a+=31;
case 7 :a+=31;
case 6 :a+=30;
case 5 :a+=31;
case 4 :a+=30;
case 3 :a+=31;
case 2 :a+=28+flag;//此法很妙
case 1 :a+=31;break;
default :printf(“Please input others\n”);
}
a +=day;//结果a=sum(before the month)+themonthday
printf(“THIS IS THE %d DAY OF %d.\n”,a,year);

    return 0;

}
int main()
{
int day,month,year;
printf(“please input the date(year.month.day):\n”);
scanf("%d.%d.%d",&year,&month,&day);
dm(year,month,day);
return 0;
}
3.说明:

你可能感兴趣的:(c,初学)