给出年月日,计算该日是该年的第几天?

2019-12-04  本文已影响0人  gtxe
#include <stdio.h>
#include <math.h>
#include <string.h>


int main()
{
    int sumday(int x,int y,int z);
    int leap(int x);
    int nian,yue,ri,sum_day;
    printf("input nian yue ri:");
    scanf("%d%d%d",&nian,&yue,&ri);
    sum_day=sumday(nian,yue,ri);
    if(leap(nian)&&yue>3)
        sum_day=sum_day+1;
    printf("是第%d天\n",sum_day);

    return 0;
}

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

int sumday(int x,int y,int z)
{
    int a[12]={31,28,31,30,31,30,31,31,30,31,30,31},sum=0,i;
    for(i=0;i<y-1;i++)
    {
        sum=sum+a[i];
    }
    sum=sum+z;
    return sum;
}
上一篇下一篇

猜你喜欢

热点阅读