题目:
输入出生年月日和现在的时间,判断经历了多少个2月29日?
分析思路:
1.2月29日,则表示闰年,因此判断从出生的年份到现在的年份的闰年,是闰年则加一;但是开始年和结束年中的月和日则需要在进行判断
2.出生年月,若大于等于3月,则该年没有经历2月29日,len-1;之后给month01初始化,以免下次循环再进入;现在年月日,若小于2月29号,则该年也没经历2月29日;
代码如下:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <malloc.h>
int main()
{
printf("请输入出生日期,亲 0_0 \n");
int year01, month01, day01, year02, month02, day02;
scanf("%d %d %d",&year01,&month01,&day01);
scanf("%d %d %d", &year02, &month02, &day02);
//int a[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int len = 0;
for (int i = year01; i <=year02; i++)
{
if (i % 400 == 0 || i % 4 == 0 && i % 100 != 0)