我的C/C++之路-006课(计算输入的时间是一年中的第几天)
当然,这个程序很简单,呵呵,简单也做了下
/*
计算输入的时间是一年中的第几天
*/
void theDayOfYear()
{
int nonleapYear[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int leapYear[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
int year,month,day,num=0;
printf("please input date like:2012 4 24 \n");
scanf("%d %d %d",&year,&month,&day);
//判断是否是闰年
if((year%4==0&&year%100!=0)||year%400==0)
{
for(int i=0;i<month-1;i++)
{
num += leapYear[i];
}
num += day;
}
else
{
for(int i=0;i<month-1;i++)
{
num += nonleapYear[i];
}
num += day;
}
printf("the day of year is:%d\n",num);
}
摘自 mzlqh的专栏
补充:软件开发 , C语言 ,