-
Notifications
You must be signed in to change notification settings - Fork 16
/
3.c
51 lines (46 loc) · 1002 Bytes
/
3.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
#include <stdio.h>
struct time_struct
{
int hour;
int minute;
int second;
};
void input_time(struct time_struct *time)
{
printf("Enter time in HH:MM:SS format: ");
scanf("%d:%d:%d", &time->hour, &time->minute, &time->second);
}
void print_time(struct time_struct time)
{
printf("Equivalent time: ");
printf("%d:%d:%d\n", time.hour, time.minute, time.second);
}
struct time_struct increment_second_in_time(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;
}
}
}
return time;
}
int main()
{
struct time_struct time;
input_time(&time);
print_time(time);
printf("Time after incrementing second: ");
time = increment_second_in_time(time);
print_time(time);
return 0;
}