红颜如霜


私信TA

用户名:uq_88586478448

访问量:918

签 名:

等  级
排  名 7945
经  验 1250
参赛次数 0
文章发表 28
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:1月到12月没什么规律,所以用个数组来累加,累加玩后在month>=3月开始判断是闰年与否,是的话sum++

注意事项:

参考代码:

#include<stdio.h>

#include<stdlib.h>

int Judge(int year)

{

    int a;

    a=(year%100==0)?((year%400==0)?1:0):((year%4==0)?1:0);

    return a;

}

int calculate(int year,int month,int day)

{

    int i,n,x,sum=0,a[12]={31,28,31,30,31,30,31,31,30,31,30,31};

    for(i=0;i<month-1;i++)

    {

        sum+=a[i];

    }

    sum+=day;

    if (month>=3)

    {

        if(Judge(year)==1)

        sum++;

    }

    return sum;

}

typedef struct DATE

{

    int year;

    int month;

    int day;

}Date;

int main()

{

    int DAYS;

    Date *p;

    p=(Date *)malloc(sizeof(Date));

    scanf("%d %d %d",&p->year,&p->month,&p->day);    

    DAYS=calculate(p->year,p->month,p->day);

    printf("%d",DAYS);

}


 

0.0分

0 人评分

  评论区

  • «
  • »