Home > Back-end >  Time conversion
Time conversion

Time:09-16

Subject program requirements to hh: mm: ss format output at a given time again after n seconds time value (more than 23:59:59 timing starts from zero),

Input format:
Input in the first row in hh: mm: ss format given starting time, the second line shows the number of seconds n (& lt; 60),

The output format:
Output in one line in hh: mm: ss format the result of the time,

Input the sample:
11:59:40
30
The output sample:
12:00:10


Code:

#include
Int main () {
Int h, m, s;
int n;
Int sum=0;
The scanf (" % d: % d: % d ", & amp; H, & amp; M, & amp; s);
The scanf (" % d ", & amp; N);
Sum=s + n.
If (sum>=60) {
Sum=sum - 60;
m++;
If (m==60) {
M=m - 60;
H++;
If (h==24) {
H=0;
}
}
}
02 02 printf (" % d: % d: % 2 d ", h, m, sum);
return 0;
}

CodePudding user response:

Just use time_t type additive, don't bother

CodePudding user response:

 # include 
Int main ()
{
Int h, m, s, n, sum=0, carry;
The scanf (" % d: % d: % d ", & amp; H, & amp; M, & amp; s);
The scanf (" % d ", & amp; N);
Sum=s + n.
//if (sum & gt;=60) {//processing second
Carry=sum/60;
Sum=sum % 60;
M +=carry;
//if (m & gt;=60) {//processing points
Carry=m/60;
M=m % 10;
H=(h + carry) % 24;
//}
//}
02 02 printf (" % d: % d: % 2 d ", h, m, sum);
return 0;
}

In fact, all if statements can not,

CodePudding user response:

 # include 

Int main ()
{
Int h, m, s;
int n;
Int sum=0;

The scanf (" % d: % d: % d ", & amp; H, & amp; M, & amp; s);
The scanf (" % d ", & amp; N);
Sum=s + n.

M +=sum/60;
The sum %=60;

H +=m/60;
M %=60;

H %=24;

# if 0
If (sum>=60) {
Sum=sum - 60;
m++;
If (m==60) {
M=m - 60;
H++;
If (h==24) {
H=0;
}
}
}
# endif

02 02 printf (" % d: % d: % 2 d \ n ", h, m, sum);

return 0;
}

For your reference ~
  • Related