细节要求:
日期1:起始日期
日期2:最终日期
需要考虑:
若两个日期在同一年,则日期2-日期1
若两个日期不在同一年,则需要考虑闰年的额外天数
代码参考:
#include <stdio.h>
int main(){
int years,monthst,dayst;
int yearend,monthend,daystend;
int total=0;
int i;
printf("请输入开始日期:");
scanf("%d/%d/%d",&years,&monthst,&dayst);
printf("请输入结束日期:");
scanf("%d/%d/%d",&yearend,&monthend,&daystend);
total = (yearend - years)*365;//相差日期的天数
total -= days(years,monthst,dayst);//开始日期
total += days(yearend,monthend,daystend);//结束日期
while(years != yearend)
{
if(years%4 == 0 && years%100 != 0 || years%400 == 0)//判断是不是润牛
total+=1;
if(total<=0)//如果开始日期大于结束日期则天数相差小于等于0
years--;<

该博客介绍如何使用C语言编程来计算两个日期之间的天数差距,考虑了同一年和不同年的情况,以及闰年的额外天数。通过输入起始日期和结束日期,程序会输出两个日期间的总天数。
1万+

被折叠的 条评论
为什么被折叠?



