-
Notifications
You must be signed in to change notification settings - Fork 0
/
46john7.c
61 lines (49 loc) · 1.13 KB
/
46john7.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
/*
Roll no:46
Batch:B
Author Name:John Joy
Date:2/09/23
Description:Time Incrementing
*/
#include <stdio.h>
struct time_struct {
int hour;
int minute;
int second;
};
void inputTime(struct time_struct *time) {
printf("Enter hour: ");
scanf("%d", &time->hour);
printf("Enter minute: ");
scanf("%d", &time->minute);
printf("Enter second: ");
scanf("%d", &time->second);
}
void displayTime(struct time_struct time) {
printf("Time: %02d:%02d:%02d\n", time.hour, time.minute, time.second);
}
void updateTime(struct time_struct *time) {
time->second++;
if (time->second >= 60) {
time->second = 0;
time->minute++;
if (time->minute >= 60) {
time->minute = 0;
time->hour++;
if (time->hour >= 24) {
time->hour = 0;
}
}
}
}
int main() {
struct time_struct time;
printf("Input new time:\n");
inputTime(&time);
printf("\nTime details:\n");
displayTime(time);
updateTime(&time);
printf("\nTime after incrementing by one second:\n");
displayTime(time);
return 0;
}