关于“三天打鱼两天晒网”的问题

#include <stdio.h>
main()
{
    int a[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31 ,30,31,30,31}};        /*定义一个二维数组,闰年,平年12个月每个月的天数*/
    int m,n,year,month,day,i,tyear;
    int total=0;
    printf("please input a date:");
    scanf("%d %d %d",&year,&month,&day);
    for(tyear=1990; tyear<year; tyear++)
    {
        if(tyear%4==0&&tyear%100!=0||tyear%400==0)         /*判断是平年还是闰年,并把输入年前几年的天数相加*/
            total+=366;
        else
            total+=365;
    }
    m=year%4==0&&year%100!=0||year%400==0;
    for(n=0; n<=(month-2); n++)
    {
        total+=a[m][n];                                                 /*将输入年前面几个月的天数相加*/
    }
    total+=day;                                                        /*将当前月的天数加上去*/
    i=total%5;
    if(i>0&&i<4)
        printf("he was fishing at that day.\n");        /*判断是打鱼还是晒网*/
    else
        printf("he was sleeping at that day.\n");
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值