1
//import library
#include <stdio.h>
#include <stdlib.h>
//declare variable structure
struct time{
int hour;
int min;
int sec;
}startTime, endTime, different, elapsed;
//mould struct and compute elapsedTime
struct time elapsedTime(struct time start, struct time end){
int secondStart, secondEnd, secondDif;
secondEnd = end.hour * 60 * 60 + end.min * 60 + end.sec;
secondStart = start.hour * 60 * 60 + start.min * 60 + start.sec;
if (secondEnd>secondStart)
secondDif = secondEnd - secondStart;
else
secondDif = secondStart - secondEnd;
different.hour = secondDif/60/60;
different.min = secondDif/60;
return different;
}
//main function
void main(){
printf("Enter start time (Hour Minute Second) using 24 hours system : ");
scanf("%d %d %d", startTime.hour, startTime.min, startTime.sec);
printf("Enter end time (Hour Minute Second) using 24 hours system : ");
scanf("%d %d %d", endTime.hour, endTime.min, endTime.sec);
elapsed = elapsedTime(startTime, endTime);
}
有人可以幫我檢查並運行代碼以檢查它是否工作嗎?使用結構的已用時間C程序
你能重新格式化代碼嗎? – rjdkolb
我的朋友嘗試運行,成功執行但未能運行。 – Jonathan
您可以在這裏查看源代碼:https://www.dropbox.com/s/watwdp7b7vmjbb8/elapsed.c?dl=0 – Jonathan