Program for converting hours into minutes and seconds - GeeksforGeeks

01 Apr, 2021
Given an integer n which is the number of hours, the task is to convert it into minutes and seconds.Examples:  
Input: 5 Output: Minutes = 300, Seconds = 18000Input: 2 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++
Java
C#
PHP
Python3
Javascript
// C++ program to convert hours// into minutes and seconds#include <bits/stdc++.h>using namespace std; // Function to convert hours// into minutes and secondsvoid ConvertHours(int n){    long long int minutes, seconds;     minutes = n * 60;    seconds = n * 3600;     cout << "Minutes = " << minutes         << ", Seconds = " << seconds << endl;} // Driver codeint main(){    int n = 5;    ConvertHours(n);    return 0;}
// 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# program to convert hours// into minutes and secondsusing System; class GFG{ // Function to convert hours into// minutes and secondsstatic void ConvertHours(int n){int minutes, seconds;     minutes = n * 60;    seconds = n * 3600;     Console.WriteLine("Minutes = " + minutes +                      ", Seconds = " + seconds);} // Driver codepublic static void Main (){    int n = 5;    ConvertHours(n);}} // This code is contributed by Ryuga
<?php// PHP program to convert hours// into minutes and seconds // Function to convert hours// into minutes and secondsfunction ConvertHours($n){    $minutes = $n * 60;    $seconds = $n * 3600;     echo "Minutes = " . $minutes .         ", Seconds = " . $seconds . "\n";} // Driver code$n = 5;ConvertHours($n); // This code is contributed// by Akanksha Rai?>
# C++ program to convert hours# into minutes and seconds  # Function to convert hours# into minutes and secondsdef ConvertHours(n):      minutes = n * 60;    seconds = n * 3600;      print("Minutes = ", minutes \         ,", Seconds = " , seconds);   # Driver coden = 5;ConvertHours(n);  # This code contributed by Rajput-Ji
<script> // JavaScript program to convert hours// into minutes and seconds // Function to convert hours    // into minutes and seconds    function ConvertHours(n) {        var minutes, seconds;         minutes = n * 60;        seconds = n * 3600;         document.write("Minutes = " + minutes + ", Seconds = " + seconds);    }     // Driver code             var n = 5;        ConvertHours(n); // This code contributed by Rajput-Ji </script>
Minutes = 300, Seconds = 18000
 
Time Complexity : O(1) 
inderDuMCA
ankthon
Akanksha_Rai
VishalBachchas
Rajput-Ji
date-time-program
Technical Scripter 2018
C++ Programs
School Programming
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
C++ Program for QuickSort
cin in C++
delete keyword in C++
Shallow Copy and Deep Copy in C++
Check if given number is perfect square
Python Dictionary
Arrays in C/C++
Reverse a string in Java
Inheritance in C++
C++ Classes and Objects