-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathovertime.c
76 lines (66 loc) · 1.12 KB
/
overtime.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<stdio.h>
#include<stdlib.h>
typedef struct time{
int hr;
int min;
int sec;
}Time;
int main()
{
Time *t,*q;
int ch;
t = (Time *)malloc(sizeof(Time));
q = (Time *)malloc(sizeof(Time));
printf("Enter the time\n");
scanf("%d%d%d",&t->hr,&t->min,&t->sec);
while(1)
{
printf("1.Update\n");
printf("2.Add\n");
scanf("%d",&ch);
if(ch==1)
{
t->sec++;
if(t->sec==60)
{
t->sec=0;
t->min++;
if(t->min==60)
{
t->min=0;
t->hr++;
if(t->hr==24)
t->hr = t->hr%24;
}
}
printf("%d::%d::%d\n",t->hr,t->min,t->sec);
}
else if(ch==2)
{
printf("Enter the time\n");
scanf("%d%d%d",&t->hr,&t->min,&t->sec);
printf("Enter the time\n");
scanf("%d%d%d",&q->hr,&q->min,&q->sec);
t->hr = t->hr+q->hr;
t->min = t->min + q->min;
t->sec = t->sec+q->sec;
if(t->sec>60)
{
t->sec = t->sec%60;
t->min++;
}
if(t->min>60)
{
t->min = t->min%60;
t->hr++;
}
if(t->hr>24)
{
t->hr = t->hr%24;
}
printf("%d::%d::%d\n",t->hr,t->min,t->sec);
}
else
exit(1);
}
}