p125 t53

#include<stdio.h>
#include<string.h>
#include <math.h>
#include<stdlib.h> 
#pragma warning(disable:4996)
/*
平年365天,其中2月28天,
闰年366天,其中2月29天.
1,3,5,7,8,10,12为31天 
*/
struct date
{
    int year, mouth, day;
};
 
int main(void)
{
    struct date d;
    int i, k = 0, day = 0;
    printf("input 年 月 日: ");
    scanf("%d%d%d", &d.year, &d.mouth, &d.day);
    ///先判断是否是闰年,若符合,则k置为1
    if (d.year % 4 == 0 && d.year % 100 != 0 || d.year % 400 == 0)
        k = 1;
    for (i = 1; i<d.mouth; i++)
    {
        if (i == 2 && k == 1)
            day += 29;
        else if (i == 2)
            day += 28;
        else if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
            day += 31;
        else
            day += 30;
    }
    day += d.day;
    printf("output:今天是第 %d 天\n", day);
    getchar();
    system("pause");
    return 0;    
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值