推算开始时间(调用函数)?

请用程序实现

根据结束时间和用时, 推算开始时间.

注意: 本题采用 24 小时制。即时间范围在0:00:00.00 ~ 23:59:59.99之间。

函数定义

void time_sub (int *start_hour, int *start_minute, double *start_second, int end_hour, int end_minute, double end_second, double duration);

参数说明

  • start_hour, 整型指针, 表示开始时间的小时
  • start_minute, 整型指针, 表示开始时间的分钟
  • start_second, 双精度浮点数指针, 表示开始时间的秒数
  • end_hour, 整型, 表示结束时间的小时
  • end_minute, 整型, 表示结束时间的分钟
  • end_second, 双精度浮点数, 表示结束时间的秒数
  • duration, 双精度浮点数, 表示用时秒数, 其值在0.00 ~ 86400.00之间

示例1

参数

end_hour = 8
end_minute = 26
end_second = 0.2
duration = 15.2

输出

start_hour: 8
start_minute: 25
start_second: 45.00

 初始代码:

#include <stdio.h>

void time_sub (int *start_hour, int *start_minute, double *start_second, int end_hour, int end_minute, double end_second, double duration) {
    // TODO 请在此处编写代码,完成题目要求
    
}

int main () {
    int start_hour, start_minute, end_hour = 8, end_minute = 26;
    double start_second, end_second = 0.2, duration = 15.2;
    time_sub(&start_hour, &start_minute, &start_second, end_hour, end_minute, end_second, duration);
    printf("start_hour: %d\nstart_minute: %d\nstart_second: %.2f\n", start_hour, start_minute, start_second);
    return 0;
}

void time_sub (int *start_hour, int *start_minute, double *start_second, int end_hour, int end_minute, double end_second, double duration)
{
		double EndDaySlipTime = 0.0;
		double StartDaySlipTime = 0.0;
		EndDaySlipTime = end_hour*3600 +  end_minute *60 + end_second;
		StartDaySlipTime = EndDaySlipTime - duration;
		*start_hour = (int)StartDaySlipTime / 3600;
		*start_minute = (int)StartDaySlipTime % 3600/60;
		*start_second = (double)((int)(StartDaySlipTime*100) % 6000 )/100.00;

}