Solved programming problem

Finding Duration of an event in C.

Source code

#include <stdio.h>

int main()

{

    int day,day1;

    int hour,hour1;

    int minute,minute1;

    int second,second1;

    int d;

    int h;

    int m;

    int s;

    printf("
Enter the Begging time (ddd-hh-min-sec):");

    scanf("%d - %d- %d - %d",&day,&hour,&minute,&second);

    printf("
Enter the Ending time(ddd-hh-min-sec):");

    scanf("%d - %d- %d - %d",&day1,&hour1,&minute1,&second1);

    ///calculating

    s=(second+second1)%60;

    m=(minute+minute1+(second+second1)/60)%60;

    h=(hour+hour1+(minute+minute1+(second+second1)/60)/60)%24;

    d=day+day1+(hour+hour1+(minute+minute1+(second+second1)/60)/60)/24;

    printf("
a%03d Days, %02d Hours, %02d Minutes, %02d seconds.
",d,h,m,s);

    return 0;

}

Output

Enter the Begging time (ddd-hh-min-sec):1-2-3-4

Enter the Ending time(ddd-hh-min-sec):5-6-7-8

006 Days, 08 Hours, 10 Minutes, 12 Seconds

Join the discussion

Add your comment