Dado un número entero n que es el número de horas , la tarea es convertirlo en minutos y segundos .
Ejemplos:
Entrada: 5
Salida: Minutos = 300, Segundos = 18000
Entrada: 2
Salida: Minutos = 120, Segundos = 7200
Acercarse:
- h horas = h * 60 minutos como 1 hora = 60 minutos.
- Del mismo modo h horas = h * 3600 segundos .
Nota: Para volver a convertir m minutos en horas, don n/60 y para s segundos s/3600 .
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program to convert hours // into minutes and seconds #include <bits/stdc++.h> 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 <stdio.h> // 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
<?php // PHP program to convert hours // into minutes and seconds // Function to convert hours // into minutes and seconds function 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 ?>
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
<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>
Producción:
Minutes = 300, Seconds = 18000
Complejidad de tiempo : O(1)
Publicación traducida automáticamente
Artículo escrito por gfg_sal_gfg y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA