Diseñar un algoritmo que permita ingresar la hora, minutos y segundos y que me calcule la hora en el siguiente segundo ("0=< H =<23", "0=< M =<59" "0=< S=<59").
Solución
- Entrada: 8 : 1:59
- Salida: 8h:2m:0s
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Main
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ingresa Hora");
int h = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Ingresa minuto");
int m = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Ingresa segundo");
int s = Convert.ToInt16(Console.ReadLine());
if (h < 24 && m < 60 && s < 60)
{
if (s < 59 && s >= 0)
{
Console.WriteLine(h + "h " + m + "m " + (s + 1) + "s");
}
else
{
if (s == 59)
{
if (m == 59)
{
if (h == 23)
{
Console.WriteLine("00h 00m 00s");
}
else
{
Console.WriteLine((h + 1) + "h 00m 00s");
}
}
else
{
Console.WriteLine(h + "h " + (m + 1) + "m 00s");
}
}
}
}
else
{
Console.WriteLine("Fuera de Rango");
}
Console.ReadLine();
}
}
}
0 comentarios:
Publicar un comentario