A day has 86,400 seconds (24*60*60). Given a number of seconds in the range of 0 to 1,000,000 seconds, output the time as days, hours, minutes, and seconds for a 24- hour clock. E.g., 70,000 seconds is 0 days, 19 hours, 26 minutes, and 40 seconds. Your function should output: Time is W days, X hours, Y minutes, and Z seconds. Your function should take the number of seconds as an integer parameter Your function MUST be named howLong.

Respuesta :

Answer:

// here is code in c++.

// include headers

#include <bits/stdc++.h>

using namespace std;

// function that calculate days, hours, minutes and seconds

void howLong(int sec)

{

   // find days

   int days=sec/86400;

   // update the seconds

   sec=sec%86400;

   // find hours

   int h=sec/3600;

   // update the seconds

   sec=sec%3600;

   // find minutes

   int min=sec/60;

   // update the seconds

   sec=sec%60;

   // output

   cout<<sec<<"seconds is "<<days<<" days,"<<h<<" hours,"<<min<<" minutes,and "<<sec<<"seconds."<<endl;

}

// driver function

int main()

{   // variable

   int sec;

   cout<<"Enter seconds:";

   // read the seconds

   cin>>sec;

   // call the function

   howLong(sec);

   

return 0;

}

Explanation:

Read the seconds from user.Then call the function howLong() with parameter seconds. In the function, it will first find the number of days by dividing the seconds with 86400 then update the remaining seconds.Next it will find the hours by dividing the remaining seconds with 3600 and update the remaining seconds.After that it will find the minutes by dividing the remaining seconds with 60 and update the remaining second.Then it will print the days, hours, minutes and seconds.

Output:

Enter seconds:70000

40seconds is 0 days,19 hours,26 minutes,and 40seconds.

Answer:

def howLong(time):

   time = int(time)

   day = time // (24*3600)

   time = time % (24*3600)

   hour = time // 3600

   time = time % 3600

   minutes = time // 60

   time = time % 60

   seconds = time

   print("Time is {}days, {}hours, {}minutes, {}seconds".format(day, hour, minutes, seconds))

howLong(70000)

Explanation:

The programming language used is python 3.

The function howLong is defined and takes one argument. this argument is converted to an integer.

Two types of division are used:

1) Floor division(//): It returns the quotient answer, in which the digits after the decimal points are removes

2) Modulo division(%): Returns the remainder value.

The day, hours, minutes and seconds are evaluated using the modulo and floor division.

The result is printed to the screen.

A picture has been attached for you to see how the code runs.

Ver imagen jehonor