#include<stdio.h>
int main()
{
int year = 1777,month = 4,day = 30,sum=0,days,days_before,i=0,days_before1,c=1;
int normal_year[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
int leap_year[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
scanf("%d",&day);
if(day<=245)
{
for(month=4;month<12;month++)
{
days = sum;
sum+= normal_year[month];
if(sum<day)
continue;
else if(sum>=day)
{
days_before = sum - day;
break;
}
}
printf("%d/%d/%d\n",year,month+1,normal_year[month]-days_before);
}
if(day>245)
{
sum = 245;
for(year=1777;sum<day;year++)
{
if(year%4==0&&year%100!=0||year%400==0)
for(;sum<day;i++ )
{
days_before1 = sum;
sum+= leap_year[i];
if(sum>day)
break;
else if(i==11&&sum<day)
{i= 0;
break;}
else if(sum ==day)
break;
}
else
for(;sum<day;i++)
{
days_before1 = sum;
sum+= normal_year[i];
if(sum>day)
break;
else if(i==11&&sum<day)
{i=0;
break;}
else if(sum == day)
break;
}
}
}
if(sum == day&&i!=11)
printf("%d/%d/%d\n",year,i+2,c);
printf("%d/%d/%d\n",year,i+1,(sum-days_before1)-(sum-day));
}
初学C语言 13年蓝桥杯高斯日记 记录
于 2024-04-01 23:23:38 首次发布
本文详细描述了一个用C语言编写的程序,用于计算给定天数对应的年月日,考虑了闰年的规则。程序针对输入的天数小于或大于245的情况分别处理,适用于公历日期计算。
摘要由CSDN通过智能技术生成