Date comparison to find which is bigger in C

前端 未结 4 1279
说谎
说谎 2020-12-19 03:48

I want to know how to find which is bigger date using a c program

kindly help me out plz....

Thanks

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-19 04:24

    #include 
    
    struct date 
    {
       int month;
       int date;
       int year;
    };
    
    
    int main(void)
    {
        int i=compare_dates (struct date d1, struct date d2);
        switch(i)
        {
           case -1:
             printf("%d/%d/%d is earlear date than %d/%d %d", D1.day, D1.month, D1.year, D2.day
           case 1: 
             printf("%d/%d/%d is later date than %d/%d/%d",D1.day,D1.month,D1.year,D2.day…
           case 0: 
             printf("%d/%d/%d is the same date than %d/%d/%d", D1.day, D1.month, D1.year, D2.day
         }
       return 0;
    }
    
    
    int compare_dates (struct date d1, struct date d2)
    {
        if (d1.year < d2.year)
           return -1;
    
        else if (d1.year > d2.year)
           return 1;
    
        if (d1.year == d2.year)
        {
             if (d1.monthd2.month)
                  return 1;
             else if (d1.dayd2.day)
                  return 1;
             else
                  return 0;
        }
    }
    

提交回复
热议问题