怎样计算是否闰年?

1个回答

  • 给定某个年/月/日的值,计算出这一天属于该年的第几天.要求写出计算闰年的函数和计算日期的函数.

    int rn(int);

    int ts(int,int,int);

    int main(int argc,char* argv[]){

    int nian,yue,ri;

    cout

    cout

    int rn(int x){if(((x%4==0)&&(x%100!=0))||(x%400==0))return 1;else return 2;}//求总天数int ts(int yue,int runnian,int ri){int tianshu,tianshu_n;

    if(yue<=8)

    tianshu=yue/2*31+(yue-1-yue/2)*30+ri;elsetianshu=(yue+1)/2*31+(yue-1-(yue+1)/2)*30+ri;

    if(runnian==1)

    tianshu_n=tianshu-1;