Hacer un programa que ingrese por teclado un número total de segundos y que luego pueda mostrar la cantidad de horas, minutos y segundos que existen en el valor ingresado
Contar el total de segundos, en una hora, minutos y segundos ingresados
Análisis
Lo que necesitamos saber es cuantos segundos tienes una hora (3600) y cuantos segundos tiene un minuto (60), para de esa manera dividir la cantidad de segundos y obtener las horas y minutos existentes.
Proceso principal para calcular horas minutos y segundos
SEGUNDOS = 3600 // Valor asignado de ejemplo.
HORAS = (SEGUNDOS / 3600) // 1 hora.
MINUTOS = (SEGUNDOS / 60) // 60 minutos.
Ahora ya sabes como convertir segundos a horas, minutos y segundos.
Pseudocódigo para calcular la cantidad de horas y minutos en una cantidad de segundos
//Mejorando el algoritmo INICIO VARIABLES : SEGUNDOS, HORAS, MINUTOS ESCRIBIR -> "Ingrese una cantidad de segundos:" LEER <– SEGUNDOS HORAS <– SEGUNDOS\3600 MINUTOS <– SEGUNDOS\60 ESCRIBIR -> "Horas:" HORAS ESCRIBIR -> "Minutos:" MINUTOS FIN RECUERDA: " \ " : Muestra División Entera " / " : Muestra División Decimal
Diagrama de flujo para convertir segundos a horas y minutos
DFD 1.0 DESCARGA CÓDIGO
PSeInt - FLEXIBLE
Algoritmo www_cisco_cursos_com Escribir "4. INGRESE UNA CANTIDAD DE SEG. Y MUESTRA LAS HOR. Y MIN. QUE EXISTEN." Escribir "" Escribir Sin Saltar "Ingrese Cantidad en Segundos : " Leer segundoss horas = TRUNC(segundoss/3600) minutos = TRUNC((segundoss - (horas*3600))/60) seg = TRUNC(segundoss - ((horas * 3600)+ (minutos*60))) Escribir "" Escribir "Horas : ", horas Escribir "Minutos : ", minutos Escribir "Segundos : ", seg FinAlgoritmo
PSeInt - ESTRICTO
Algoritmo www_cisco_cursos_com Definir segundoss, minutos, horas, seg como Entero; Escribir "4. INGRESE UNA CANTIDAD DE SEG. Y MUESTRA LAS HOR. Y MIN. QUE EXISTEN."; Escribir ""; Escribir Sin Saltar "Ingrese Cantidad en Segundos : "; Leer segundoss; horas <- TRUNC(segundoss/3600); minutos <- TRUNC((segundoss - (horas*3600))/60); seg <- TRUNC(segundoss - ((horas * 3600)+ (minutos*60))); Escribir ""; Escribir "Horas : ", horas; Escribir "Minutos : ", minutos; Escribir "Segundos : ", seg; FinAlgoritmo
Análisis de código
- segundos = Guarda la cantidad de segundos ingresados por teclado.
- horas = Guarda las horas, considerando que cada hora tiene 3600 segundos.
- minutos = Guarda los minutos, dónde cada minuto tiene 60 segundos.
- seg = Guarda los segundos restante de las horas y minutos ya obtenidos.
- INGRESO: Ingresa la cantidad de segundos
- PROCESO: Divide los segundos entre 3600 para obtener las horas y el restante entre 60 para obtener los minutos, los sobrantes serán los segundos; en la variable seg.
- SALIDA: Muestra la variable horas, minutos y seg.
Lenguaje C
#include<stdio.h> int main() { float horas, minutos, segundos; printf("04. MUESTRA LAS HORAS Y MINUTOS EN UN TOTAL DE SEGUNDOS.\n\n"); printf("Ingrese Cantidad en Segundos : "); scanf("%f",&segundos); horas = (segundos/3600); minutos = (segundos/60); printf("Horas : %.0f\n",horas); printf("Minutos : %.0f\n",minutos); return 0; }
C++
#include<iostream> using namespace std; int main() { int horas, minutos, segundos; cout << "04. MUESTRA LAS HORAS Y MINUTOS EN UN TOTAL DE SEGUNDOS.\n\n"; cout << "Ingrese Cantidad en Segundos : "; cin >> segundos; horas = (segundos/3600); minutos = (segundos/60); cout << "Horas : " << horas << endl; cout << "Minutos : " << minutos << endl; return 0; }
C# - CSharp
using System; using System.Collections.Generic; using System.Text; namespace www_cisco_cursos_com { class Ejercicio04 { static void Main(string[] args) { int horas, minutos, segundos; Console.WriteLine("04. MUESTRA LAS HORAS Y MINUTOS EN UN TOTAL DE SEGUNDOS.\n"); Console.Write("Ingrese Cantidad en Segundos : "); segundos = int.Parse(Console.ReadLine()); horas = segundos/3600; minutos = segundos/60; Console.WriteLine("\nHoras : " + horas); Console.WriteLine("Minutos : " + minutos); Console.ReadLine(); } } }
PYTHON
print("04. VER CANTIDAD DE HORAS Y MINUTOS EN LOS SEGUNDOS INGRESADOS.") segundos = float(input("Ingrese Cantidad en Segundos : ")) horas = round(segundos/3600) minutos = round(segundos/60) print("Horas : ",horas) print("Minutos : ",minutos)
print("04. MUESTRA LOS VALORES RESTANTES DE HORAS, MINUTOS Y SEGUNDOS.") segundos = float(input("Ingrese Cantidad en Segundos : ")) hor = round(segundos/3600) min = round((segundos - (hor * 3600))/60) seg = round(segundos - ((hor * 3600) + (min * 60))) print("HORAS : ", hor) print("MINUTOS : ", min) print("SEGUNDOS: ", seg)
Java NetBeans - CONSOLA
package www_cisco_cursos_com; import java.util.Scanner; public class www_cisco_cursos_com { public static void main(String[] args) { Scanner ingreso=new Scanner(System.in); int segundos, minutos, horas; System.out.print("04. MOSTRAR LA CANTIDAD DE HORAS Y MINUTOS.\n\n"); System.out.print("Ingrese una cantidad en segundos : "); segundos = Integer.parseInt(ingreso.next()); horas = segundos/3600; minutos = segundos/60; System.out.println("EN HORAS : " + horas); System.out.println("EN MINUTOS : " + minutos); } }
Java NetBeans - FORMULARIO
PROPIEDAD NAME : jTxt_seg[JTextField] jTxt_hr[JTextField] jTxt_min[JTextField] jBtn_Calcular[jButton] PROPIEDAD TEXT : jLabel1.setText("04. Ingrese una cantidad en segundos y muestre la cantidad de horas y minutos que existen."); jLabel2.setText("MINUTOS"); jLabel4.setText("SEGUNDOS"); jLabel5.setText("HORAS"); jBtn_Calcular.setText("CALCULAR"); PROPIEDAD FONT : jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); PROPIEDAD EDITABLE : jTxt_hr.setEditable(false); jTxt_min.setEditable(false);
* Control Button [CÓDIGO] [EVENTO : ActionPerformed]
private void jBtn_CalcularActionPerformed(java.awt.event.ActionEvent evt) { int segundos, minutos, horas; segundos = Integer.parseInt(jTxt_seg.getText()); minutos = segundos/3600; horas = segundos/60; jTxt_hr.setText(String.valueOf(minutos)); jTxt_min.setText(String.valueOf(horas)); }
VISUAL BASIC .NET - CONSOLA
Imports System.Console Module Ejercicio04 Dim Segundos, Horas, Minutos As Integer Sub Main() WriteLine("04. MUESTRA LAS HORAS Y MINUTOS EN UN TOTAL DE SEGUNDOS") WriteLine("") Write("Ingrese Total de Segundos : ") Segundos = ReadLine() WriteLine("") Horas = Segundos \ 3600 Minutos = Segundos \ 60 WriteLine("En Horas hay : " & Horas) WriteLine("En Minutos hay : " & Minutos) ReadLine() End Sub End Module
VISUAL BASIC .NET - FORMULARIO
Private Sub Btn_Calcular_Click(sender As Object, e As EventArgs) Handles Btn_Calcular.Click Dim Segundos, Horas, Minutos As Double Segundos = Txt_Seg.Text Horas = Segundos \ 3600 Minutos = Segundos \ 60 Txt_Hrs.Text = Horas Txt_Min.Text = Minutos End Sub
DIVISION ENTERA USANDO : \
Java Script
<html> <title>Ejercicio 04:</title> <head> <script language="JavaScript" type="text/javascript"> function segundos(){ var xsegundos=ejercicio4.segundo.value; document.getElementById('hora').value=xsegundos/3600; document.getElementById('minuto').value=xsegundos/60; } </script> </head> <body> <form method="get" name="ejercicio4"> INGRESE TOTAL DE SEGUNDOS : <input name="segundo" type="text" > <br> <input type="button" value="CALCULAR" onClick="segundos()" > <br> HORAS : <input name="hora" id="hora" type="text" > <br> MINUTOS : <input name="minuto" id="minuto" type="text" > <br> </form> </body> </html>
PHP
<html> <head> <title>Secuencial - Ejercicio 04</title> </head> <body> <form name="form1" method="post" action="segundos.php"> INGRESE TOTAL DE SEGUNDOS : <input name="segundos" type="text" id="segundos"> <BR/> <input type="submit" name="submit" value="CALCULAR"> </form> </body> </html> <?php $xsegundos = $_POST['segundos']; $xhoras = $xsegundos/3600; $xminutos = $xsegundos/60; print 'Segundos Ingresados : ' . $xsegundos; print '<br>En Horas : ' . intval($xhoras); print '<br>En Minutos : ' . $xminutos; ?>
Excel VBA - Formulario
Private Sub btn_calcular_Click() Dim Segundos As Integer Segundos = txt_seg.Text txt_hr.Text = Round(Segundos / 3600, 0) txt_min.Text = Round(Segundos / 60, 0) End Sub
Excel VBA - MODULO
Sub Segundos2() Dim Segundos As Integer Dim horas As Integer Dim minutos As Integer Segundos = Range("C12").Value horas = Round(Segundos / 3600, 0) minutos = Round(Segundos / 60, 0) Range("F12").Value = horas Range("G12").Value = minutos End Sub
Excel VBA - MODULO (InputBox)
Sub Segundos() Dim Segundos As Integer Dim horas As Integer Dim minutos As Integer Segundos = InputBox("INGRESE TOTAL DE SEGUNDOS") horas = Round(Segundos / 3600, 0) minutos = Round(Segundos / 60, 0) MsgBox "HORAS : " & horas & vbNewLine & "MINUTOS : " & minutos End Sub
Convertir de segundos a horas, minutos y segundos
La formula seria dividir los segundos entre 3600 que es la cantidad de segundos que tiene una hora y para minutos dividir los segundos sobrantes entre 60.
Algoritmo para convertir segundos a horas, minutos y segundos
Se tiene que declarar las variables para guardar las horas, minutos y segundos restantes y hacer los calculos matemáticos en cada proceso.
Algoritmo para sumar horas, minutos y segundos en python
Se tendría que convertir todas las horas y minutos a segundos la final sumar con los segundos ingresados para convertir todo a un tiempo en segundos y luego hacer el mismo proceso en reversa.
Conversor de segundos a horas, minutos y segundos
Existen muchas web que hacen esa conversión de tiempo a segundos, lo que encontrarás en nuestra web es códigos de programación que te explican ese proceso.
¿Cómo convertir segundos a tiempo (hh mm ss) o viceversa?
+ para convertir segundos a horas es : segundos / 3600.
+ Para convertir segundos a minutos es : segundos / 60.
Python, ¿Cómo convierto segundos a horas, minutos y segundos?
Este sería el código básico en python:
- horas = round(segundos/3600)
- minutos = round(segundos/60)
- print("Horas : ",horas)
- print("Minutos : ",minutos)
Deja una respuesta