请阅读以下代码并指导我如何将int elapsedTime作为结构类型返回为第三次结构例如time3并显示它?
#include <stdio.h>
#include <stdlib.h>>
#include <math.h>
#include "Time.h"
void elapsedTime(struct time time1, struct time time2); // Prototype
int main(){
struct time time1 = {3, 45, 15};
struct time time2 = {9, 44, 03};
elapsedTime(time1, time2);
return 0;
}
void elapsedTime(struct time time1, struct time time2){
int elapsedTime = ((time1.Hours * MINUTES_IN_AN_HOUR *
SECONDS_IN_A_MINUTE) + (time1.Minutes * SECONDS_IN_A_MINUTE) +
time1.Seconds) - ((time2.Hours * MINUTES_IN_AN_HOUR *
SECONDS_IN_A_MINUTE) + (time2.Minutes * SECONDS_IN_A_MINUTE) +
time2.Seconds);
printf(" %d \n", abs(elapsedTime));
return;
}
头文件中的结构:
struct time{
int Hours;
int Seconds;
int Minutes;
};
答案 0 :(得分:1)
整数师是你的朋友。您需要执行以下操作:
result.Hours = et / 3600;
et -= (result.Hours * 3600);
result.Minutes = et / 60;
et -= (result.Minutes * 60);
result.Seconds = et;