输入某年某月某日,计算出这一天是该年的第几天?

来源:百度知道 编辑:UC知道 时间:2024/06/15 04:48:46
最好用C写,希望在发之前自己先运行一下,谢谢。。我用的是VC6.0

//输入年月日,输出是该年第几天
#include<stdio.h>
int sum(int month,int day)
{
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int i;
for(i=1;i<month;i++)
day+=days[i];
return(day);
}

int leap(year)
{
int leap=0;
if((year%4==0&&year%100!=0)||(year%400==0))
leap=1;
return leap;
}

void main()
{
int year,month,day,num;
printf("Please input year,month,day:\n");
scanf("%d,%d,%d",&year,&month,&day);
num=sum(month,day);
if(leap(year)&&month>=3)
num++;
printf("It is the %dth day.\n",num);
}

我写过一个
还能算奥运倒计时
要不要看看

兄弟,这个很简单的, 不用自己写了.
在C的time.h里面已经定义了一些函数, 就能满足你的要求了.
struct tm 的成员描述为:
tm_sec seconds after the minute 0-61*
tm_min minutes after the hour 0-59
tm_hour hours since midnight 0-23
tm_mday day of the month 1-31
tm_mon months since January 0-11