C语言实现,计算两天之间相差的天数

给定两天的年月日,计算相差的天数,年份从小到大。

#include

//给定一个年月日,计算这一年已经过的天数
int total_day(int year,int month,int day)
{
    int sum = 0;
    switch(month)
    {
        case 1:sum = day;
                break;
        case 2:sum = 31 + day;
                break;
        case 3:sum = 59 + day;
                break;
        case 4:sum = 90 + day;
                break;
        case 5:sum = 120 + day;
                break;
        case 6:sum = 151 + day;
                break;
        case 7:sum = 181 + day;
                break;
        case 8:sum = 212 + day;
                break;
        case 9:sum = 243 + day;
                break;
        case 10:sum = 273 + day;
                break;
        case 11:sum = 304 + day;
                break;
        case 12:sum = 334 + day;
                break;
        default :
        printf("输入的月份有错误\n");
        break;
    }
    if(month >2)
    {
        if(((year % 4 == 0)&&(year % 100 !=0))||(year % 400) == 0){
         sum = sum + 1;
        }
    }
    return sum;
}
//年与年相差的天数
int total_year_day(int year1,int year2)
{
    int sum_year_day = 0;
    int i = 0;
    sum_year_day = (year2 - year1) * 365;
    for(i=year1 ; i


你可能感兴趣的:(c)