Computer Science, asked by um87946, 6 months ago

Write an algorithm and draw a flowchart for a program that take input value as seconds from user then convert
these seconds into number of days, hours, minutes and seconds.

Answers

Answered by mayanksr28
4

Answer:

Number of days = ⌊ n / (24 * 3600) ⌋

Number of Hours = ⌊ (n % (24 * 3600)) / 3600 ⌋

Number of Minutes = ⌊ (n % (24 * 3600 * 3600)) / 60 ⌋

Number of Seconds = ⌊ (n % (24 * 3600 * 3600 * 60)) / 60 ⌋

Explanation:

For C++:

// C++ program to convert seconds  

// into days, hours,minutes,seconds  

#include <bits/stdc++.h>  

using namespace std;  

 

// function convert second into day  

// hours, minutes and seconds  

void ConvertSectoDay(int n)  

{  

   int day = n / (24 * 3600);  

 

   n = n % (24 * 3600);  

   int hour = n / 3600;  

 

   n %= 3600;  

   int minutes = n / 60 ;  

 

   n %= 60;  

   int seconds = n;  

     

   cout << day << " " << "days " << hour  

        << " " << "hours " << minutes << " "  

        << "minutes " << seconds << " "  

        << "seconds "  << endl;  

}  

   

// Driver code  

int main()  

{  

   // Given n is in seconds  

   int n = 129600;  

   ConvertSectoDay(n);  

   return 0;  

}  

Output :

1 days 12 hours 0 minutes 0 seconds

For Java:

// Java program to convert seconds  

// into days, hours,minutes,seconds  

import java.io.*;  

 

class GFG  

{  

   // function convert second into day  

   // hours, minutes and seconds  

   static void ConvertSectoDay(int n)  

   {  

       int day = n / (24 * 3600);  

     

       n = n % (24 * 3600);  

       int hour = n / 3600;  

     

       n %= 3600;  

       int minutes = n / 60 ;  

     

       n %= 60;  

       int seconds = n;  

         

       System.out.println( day + " " + "days " + hour  

                          + " " + "hours " + minutes + " "

                          + "minutes " + seconds + " "

                          + "seconds ");  

   }  

     

   // Driver code  

   public static void main (String[] args)  

   {  

       // Given n is in seconds  

       int n = 129600;  

       ConvertSectoDay(n);  

 

   }  

}  

Output :

1 days 12 hours 0 minutes 0 seconds

For Python3:

filter_none

edit

play_arrow

brightness_4

# Python3 program to convert seconds  

# into days, hours, minutes, seconds  

 

# Function convert second into day  

# hours, minutes and seconds  

def ConvertSectoDay(n):  

 

   day = n // (24 * 3600)  

 

   n = n % (24 * 3600)  

   hour = n // 3600

 

   n %= 3600

   minutes = n // 60

 

   n %= 60

   seconds = n  

     

   print(day,"days", hour, "hours",  

         minutes, "minutes",  

         seconds, "seconds")  

 

 

# Driver code  

 

# Given n is in seconds  

n = 129600

ConvertSectoDay(n)  

Output :

1 days 12 hours 0 minutes 0 seconds

For C#:

// C# program to convert seconds  

// into days, hours,minutes,seconds  

using System;  

 

class GFG {  

     

   // function convert second into day  

   // hours, minutes and seconds  

   static void ConvertSectoDay(int n)  

   {  

       int day = n / (24 * 3600);  

     

       n = n % (24 * 3600);  

       int hour = n / 3600;  

     

       n %= 3600;  

       int minutes = n / 60 ;  

     

       n %= 60;  

       int seconds = n;  

         

       Console.WriteLine( day + " "  

             + "days " + hour + " "  

         + "hours " + minutes + " "

       + "minutes " + seconds + " "

                       + "seconds ");  

   }  

     

   // Driver code  

   public static void Main ()  

   {  

         

       // Given n is in seconds  

       int n = 129600;  

         

       ConvertSectoDay(n);  

   }  

}  

Output :

1 days 12 hours 0 minutes 0 seconds

For PHP:

filter_none

edit

play_arrow

brightness_4

<?php  

// PHP program to convert seconds  

// into days, hours,minutes,seconds  

 

// function convert second into day  

// hours, minutes and seconds  

function ConvertSectoDay($n)  

{  

   $day = floor($n / (24 * 3600));  

 

   $n = ($n % (24 * 3600));  

   $hour = $n / 3600;  

 

   $n %= 3600;  

   $minutes = $n / 60 ;  

 

   $n %= 60;  

   $seconds = $n;  

     

echo ("$day days $hour hours $minutes minutes $seconds seconds");  

         

}  

 

// Driver code  

{  

     

   // Given n is in seconds  

   $n = 129600;  

   ConvertSectoDay($n);  

   return 0;  

}  

Output :

1 days 12 hours 0 minutes 0 seconds

#HeheheMan

Hope It Helps

See Ya Soon :)

Similar questions