# Program for converting hours into minutes and seconds

• Last Updated : 11 May, 2022

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:

## C++

 `// C++ program to convert hours` `// into minutes and seconds` `#include ` `using` `namespace` `std;`   `// Function to convert hours` `// into minutes and seconds` `void` `ConvertHours(``int` `n)` `{` `    ``long` `long` `int` `minutes, seconds;`   `    ``minutes = n * 60;` `    ``seconds = n * 3600;`   `    ``cout << ``"Minutes = "` `<< minutes` `         ``<< ``", Seconds = "` `<< seconds << endl;` `}`   `// Driver code` `int` `main()` `{` `    ``int` `n = 5;` `    ``ConvertHours(n);` `    ``return` `0;` `}`

## C

 `// C program to convert hours` `// into minutes and seconds` `#include `   `// Function to convert hours` `// into minutes and seconds` `void` `ConvertHours(``int` `n)` `{` `    ``long` `long` `int` `minutes, seconds;`   `    ``minutes = n * 60;` `    ``seconds = n * 3600;` `    `  `    ``printf``(``"Minutes = %lld, Seconds = %lld\n"``,minutes,seconds);` `}`   `// Driver code` `int` `main()` `{` `    ``int` `n = 5;` `    ``ConvertHours(n);` `    ``return` `0;` `}`   `// This code is contributed by kothavasaakash.`

## Java

 `// Java program to convert hours` `// into minutes and seconds`   `import` `java.io.*;`   `class` `GFG {`     `// Function to convert hours` `// into minutes and seconds` ` ``static` `void` `ConvertHours(``int` `n)` `{` ` ``int` `minutes, seconds;`   `    ``minutes = n * ``60``;` `    ``seconds = n * ``3600``;`   `    ``System.out.println( ``"Minutes = "` `+ minutes` `        ``+ ``", Seconds = "` `+ seconds);` `}`   `// Driver code` `    ``public` `static` `void` `main (String[] args) {` `    ``int` `n = ``5``;` `    ``ConvertHours(n);` `    ``}` `    `  `}` `// This code is contributed by inder_verma..`

## C#

 `// C# program to convert hours ` `// into minutes and seconds ` `using` `System;`   `class` `GFG` `{ `   `// Function to convert hours into ` `// minutes and seconds ` `static` `void` `ConvertHours(``int` `n) ` `{ ` `int` `minutes, seconds; `   `    ``minutes = n * 60; ` `    ``seconds = n * 3600; `   `    ``Console.WriteLine(``"Minutes = "` `+ minutes + ` `                      ``", Seconds = "` `+ seconds); ` `} `   `// Driver code ` `public` `static` `void` `Main ()` `{ ` `    ``int` `n = 5; ` `    ``ConvertHours(n); ` `}` `} `   `// This code is contributed by Ryuga`

## PHP

 ``

## Python3

 `# C++ program to convert hours` `# into minutes and seconds` ` `  `# Function to convert hours` `# into minutes and seconds` `def` `ConvertHours(n):` ` `  `    ``minutes ``=` `n ``*` `60``;` `    ``seconds ``=` `n ``*` `3600``;` ` `  `    ``print``(``"Minutes = "``, minutes \` `         ``,``", Seconds = "` `, seconds);`   ` `  `# Driver code` `n ``=` `5``;` `ConvertHours(n);`     `# This code contributed by Rajput-Ji`

## Javascript

 ``

Output:

`Minutes = 300, Seconds = 18000`

Time Complexity : O(1)

My Personal Notes arrow_drop_up
Recommended Articles
Page :