Menu Close

Convert seconds to hours – HMS format.

Surya was used to wear a smartwatch when he was in the Treadmill and during Cycling.  Surya’s Smart watch displays the total workout time in seconds.
But Surya would like to know the time he spent for workout in H:M:S format.
Can you help surya in knowing the time he spent on workout in the prescribed format?

Input:
7845

Output:
2H:10M:45S
#include <stdio.h>
int main()
{
    int sec,h,m,s;
    scanf("%d",&sec);
    h=sec/3600;
    m=(sec-(h*3600))/60;
    s=(sec-(h*3600)-m*60);
    printf("%dH:%dM:%dS",h,m,s);
	return 0;
}

INPUT_1:
7845

OUTPUT:
2H:10M:45S


INPUT_2:
1000

OUTPUT:
0H:16M:40S


INPUT_3:
10000

OUTPUT:
2H:46M:40S



INPUT_4:
9871

OUTPUT:
2H:44M:31S


INPUT_5:
6300

OUTPUT:
1H:45M:0S


INPUT_6:
3700

OUTPUT:
1H:1M:40S


ILLUSTRATION

Executed using gcc

Morae Q!