קוד:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int clock(int hour,int hour1,int min,int min1,int sec,int sec1)
{
int temp,totalseconds,totalseconds1;
totalseconds=(hour*60+min)*60+sec;
totalseconds1=(hour1*60+min1)*60+sec1;
temp=abs(totalseconds1-totalseconds);
return temp;
}
void PrintDisplayOfSec(int nTotalSec)
{
// הגדרת משתנים עבור חלקי השעה
int nHour;
int nSed;
int nMin;
// קביעת מספר הדקות היוצאות ממספר השניות
nMin = nTotal / 60;
// בדיקה כמה שניות ישארו ללא דקה מאגדת
nSec = nTotal % 60;
// ביצוע אותה פעולה שעשינו על מספר השניות הכללי לדקות
nHour = nMin / 60;
nMin = nMin % 60;
printf("%d : %d : %d", nHour, nMin, nSec);
}
void main(int temp)
{
int hour,hour1,min,min1,sec,sec1;
printf("enter hour,min and sec of first time");
scanf("%d%d%d",&hour,&min,&sec);
printf("enter hour,min and sec of second time");
scanf("%d%d%d",&hour1,&min1,&sec1);
while(hour<=24 && hour >0 && min<=60 && min>0 && sec<=60 && sec>0 && hour1<=24 && hour1 > 0 && min1<=60 && min1>0 && sec1<=60 && sec1>0 )
{
//קריאה לפונקציה
PrintDisplayOfSec(clock(hour,hour1,min,min1,sec,se c1));
else
printf("enter hour,min and sec of first time");
scanf("%d%d%d",&hour,&min,&sec);
printf("enter hour,min and sec of second time");
scanf("%d%d%d",&hour1,&min1,&sec1);
}
PrintDisplayOfSec(clock(hour,hour1,min,min1,sec,se c1));
}