VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-convert-given-weeks-to-hours/

⇱ Program to convert given weeks to hours - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to convert given weeks to hours

Last Updated : 20 Feb, 2024

Given a positive integer W which represents the number of weeks, your task is to convert it to the total number of hours.

Examples:

Input: W=15
Output: 2520

Input: W=1
Output: 168

Approach: To solve the problem, follow the below idea:

The problem can be solved using simple mathematical conversions:

  • 1 Week = 7 days
  • 1 Day = 24 hours

Step-by-step algorithm:

  • Create a function WeekToDays() that converts the number of weeks to equivalent number of days using the formula:
    • 1 Week = 7 days
  • Use a function DaysToWeek() to convert the days to equivalent number of hours using the formula:
    • 1 Day = 24 hours

Below is the implementation of the algorithm:


Output
2520
168

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

Comment
Article Tags:
Article Tags: