Challenge: Hours and Minutes
Completed
Read a number of minutes and print how many whole hours and minutes that is, like 2 h 15 min.
Input
One integer: the total minutes (0 or more).
Output
One line: H h M min.
Example
Input
135
Output
2 h 15 min
Editor
C++
Hints
Hours: total / 60 (integer division).
Minutes left over: total % 60.
Solution explanation
Integer division gives the whole hours and the remainder % gives the minutes left over.
Show solution
#include <iostream>
using namespace std;
int main() {
int total;
cin >> total;
cout << total / 60 << " h " << total % 60 << " min\n";
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module