全部代码

初试结构

判断到月底还有几天,故意写的很长

code 初试结构.c
#include<stdio.h>
#include <stdbool.h>

struct date{
    int year;
    int month;
    int day;
};

struct daysofmonth{
    int jan; int feb;
    int mar; int apr;
    int may; int jun;
    int jul; int aug;
    int sep; int oct;
    int nov; int dec;  
};

struct daysofmonth fdaysofmonth(struct date d);
bool isrunnian(struct date d);

int main()
{
    struct date d;
    printf("请输入年月日:");
    scanf("%d %d %d",&d.year,&d.month,&d.day);
    struct daysofmonth a=fdaysofmonth(d);
    int dom[]={a.jan, a.feb, a.mar, a.apr, a.may, a.jun,
                a.jul, a.aug, a.sep, a.oct, a.nov, a.dec};
    printf("到月底还有 %d 天\n",dom[d.month-1]-d.day);
    return 0;
}

bool isrunnian(struct date d)
{
    return (d.year % 4 == 0 && d.year % 100 != 0) || (d.year % 400 == 0);
}

struct daysofmonth fdaysofmonth(struct date d)
{
    struct daysofmonth output;
    if (isrunnian(d))
        output=(struct daysofmonth){31,29,31,30,31,30,31,30,31,30,31,30};
    else
        output=(struct daysofmonth){31,28,31,30,31,30,31,30,31,30,31,30};
    return output;
}

本站累计访问

访问计数