Thursday, September 13, 2018

UNITS OF TIME

  • Problem Description

    Develop a program that begins by reading a number of seconds from the user.

    Then your program should display the equivalent amount of time in the form D:HH:MM:SS, where D, HH, MM, and SS represent days, hours, minutes and seconds respectively. 

    The hours, minutes and seconds should all be formatted so that they occupy exactly two digits, with a leading 0 displayed if necessary.
  • CODING ARENA::
  • #include <stdio.h>
    int main()
    {int a;
     int d,m,s,h;
     scanf("%d",&a);
     if(a>0)
     {
     d=a/(24*3600);
     h=(a%(24*3600))/3600;
     m=(a%3600)/60;
     s=(a%3600)%60;
     printf("The Duration is %d days %d hours %d minutes %d seconds",d,h,m,s);
     }
     else
     {
       printf("0");
     }
     return 0;
    }
  • Test Case 1

    Input (stdin)
    563685
    
    
    Expected Output
    The Duration is 6 days 12 hours 34 minutes 45 seconds
  • Test Case 2

    Input (stdin)
    0
    
    
    Expected Output
    0

No comments:

Post a Comment