hz_king 2014-12-22 05:13 采纳率: 50%
浏览 1589
已采纳

c语言学习基础差,求指导

用结构体表示日期,输入一个日期(年、月、日),计算从输入年的1月1日到输入的日期的总天数days并输出。

  • 写回答

2条回答 默认 最新

  • 漂泊者011 2014-12-22 05:54
    关注
    struct tm  when;
    __time64_t now, result;
    int        days;
    char       buff[80];
    
    time( &now );
    _localtime64_s( &when, &now );
    asctime_s( buff, sizeof(buff), &when );
    printf( "Current time is %s\n", buff );
    days = 20;
    when.tm_mday = when.tm_mday + days;
     result=mktime( &when ) ;
     double d=difftime(result,now);
     int nDays=d/60/60/24;
        可以计算出结果差20天
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?