Skip to content

Commit c009347

Browse files
committed
Uploaded file
1 parent 1487969 commit c009347

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

timeInSeconds.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
6+
int timeToSeconds(int hh, int mm, int ss)
7+
{
8+
int sec;
9+
sec = hh * 60 * 60 + mm * 60 + ss;
10+
return sec;
11+
}
12+
13+
int* secondsToTime(int seconds)
14+
{
15+
int *time = (int*)malloc(3*sizeof(int));
16+
int hh = seconds / (60 * 60);
17+
int mm = seconds / 60 - hh * 60;
18+
int ss = seconds - (hh * 60 *60 ) - (mm*60);
19+
20+
time[0] = hh;
21+
time[1] = mm;
22+
time[2] = ss;
23+
24+
return time;
25+
}
26+
27+
int main()
28+
{
29+
int seconds =0;
30+
int *time;
31+
short int choice;
32+
printf("\n1.Convert time to seconds\n2.Convert seconds to time\n");
33+
printf("\nEnter your choice: ");
34+
scanf("%hu", &choice);
35+
36+
switch(choice)
37+
{
38+
case 1: {
39+
int hh, mm ,ss;
40+
printf("Enter time in hh: mm: ss ");
41+
scanf("%d %d %d",&hh, &mm, &ss);
42+
seconds = timeToSeconds(hh, mm, ss);
43+
break;
44+
}
45+
case 2:{
46+
int seconds;
47+
printf("Enter seconds:");
48+
scanf("%d", &seconds);
49+
time = secondsToTime(seconds);
50+
break;
51+
}
52+
}
53+
if(choice==1)
54+
printf("Time in seconds: %d", seconds);
55+
else
56+
printf("Time in HH : MM : SS \t %d :%d :%d \n", time[0], time[1], time[2]);
57+
58+
return 0;
59+
60+
}

0 commit comments

Comments
 (0)