File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Program to update the time by one second
2
+
3
+ #include <stdio.h>
4
+
5
+ struct time
6
+ {
7
+ int hour ;
8
+ int minutes ;
9
+ int seconds ;
10
+ };
11
+
12
+ int main (void )
13
+ {
14
+ struct time timeUpdate (struct time now );
15
+ struct time currentTime , nextTime ;
16
+
17
+ printf ("Enter the time (hh:mm:ss): " );
18
+ scanf ("%i:%i:%i" , & currentTime .hour ,
19
+ & currentTime .minutes , & currentTime .seconds );
20
+
21
+ nextTime = timeUpdate (currentTime );
22
+
23
+ printf ("Updated time is %.2i:%.2i:%.2i\n" , nextTime .hour ,
24
+ nextTime .minutes , nextTime .seconds );
25
+
26
+ return 0 ;
27
+ }
28
+
29
+ // Function to update the time by one second
30
+
31
+ struct time timeUpdate (struct time now )
32
+ {
33
+ ++ now .seconds ;
34
+
35
+ if ( now .seconds == 60 ) { // next minute
36
+ now .seconds = 0 ;
37
+ ++ now .minutes ;
38
+
39
+ if ( now .minutes == 60 ) { // next hour
40
+ now .minutes = 0 ;
41
+ ++ now .hour ;
42
+
43
+ if ( now .hour == 24 ) // midnight
44
+ now .hour = 0 ;
45
+ }
46
+ }
47
+
48
+ return now ;
49
+ }
You can’t perform that action at this time.
0 commit comments