Challenge: Calculate Hours, Minutes, and Seconds

Solve a slightly more tricky challenge in this lesson.

Problem statement

In this challenge, you are given the total number of seconds, and your task is to display the number of hours, minutes, and seconds in it.

1 minute=60 seconds1\ minute = 60\ seconds

1 hour=60 minutes1\ hour= 60\ minutes

Input

We have already initialized the variable total_seconds at the backend.

int total_seconds = 3870;

Output

Your code should have the following output:

hours = 1
minutes = 4
seconds = 30

📝 Please use the variables total_seconds for the input and hours, minutes, and seconds for the output, or your code will not execute.

Coding exercise

Before diving directly into the solution, try to solve it yourself.Then, check if your code passes all the test cases.

Good luck! 👍

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy