VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-for-converting-hours-into-minutes-and-seconds/

⇱ Program for converting hours into minutes and seconds - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program for converting hours into minutes and seconds

Last Updated : 13 Mar, 2023

Given an integer n which is the number of hours, the task is to convert it into minutes and seconds.

Examples: 

Input:
Output: Minutes = 300, Seconds = 18000

Input:
Output: Minutes = 120, Seconds = 7200 


Approach: 
 

  • h hours = h * 60 minutes as 1 hour = 60 minutes.
  • Similarly h hours = h * 3600 seconds.


Note: To convert m minutes back into hours, do n / 60 and for s seconds s / 3600.
Below is the implementation of the above approach: 
 


Output: 
Minutes = 300, Seconds = 18000

 

Time Complexity : O(1)
Auxiliary Space: O(1)

Comment