Wednesday, February 20, 2019

Time decomposition

Write a program that, given a number of seconds n, prints the number of hours, minutes and seconds represented by n.

Input: Input consists of a natural number n.

Output: Print three natural numbers h, m, s such that 3600h+60m+s=n, with m<60 and s<60.

#include <iostream> 
using namespace std;
          
int main (){
    int n;
    cin >> n;
    
    int h, m, s;
    h = n/3600;
    s = n%60;
    m = (n-s-(3600*h))/60;
    
    cout << h <<' '<< m << ' ' << s << endl;
}

No comments:

Post a Comment

Modelo OSI

Open System Interconnection , Interconexión de Sistemas Abiertos, es un modelo para estudiar las categorías en que se pueden dividir los pr...