Challenge: Calculate Hours, Minutes, and Seconds
Solve a slightly more tricky challenge in this lesson.
We'll cover the following
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.
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 andhours
,minutes
, andseconds
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.
Continue your learning journey with a 14-day free trial.
By signing up, you agree to Educative's Terms of Service and Privacy Policy