Home > Back-end >  Please help to have a look at the C language programming problem
Please help to have a look at the C language programming problem

Time:03-23

Children what won't greatly, help, crab crab crab crab  ~

CodePudding user response:

You want pure C
#include

Int analysisHourAndMin pTime (char *);
Void main ()
{
Char preTime []="10:30";
Char nexTime []="" ";

Int nPreTime=analysisHourAndMin (preTime);
Int nNextTime=analysisHourAndMin (nexTime);

Int nCurTime=nNextTime - nPreTime;
Printf (" % d: % d ", nCurTime/60, 60 nCurTime %);

}

Int analysisHourAndMin (char * pTime)
{
Int nHour=(pTime [0] - '0') * 10 + (pTime [1] - '0');
Int nMin=(pTime [3] - '0') * 10 + (pTime [4] - '0');
Return nHour * 60 + nMin;
}

CodePudding user response:

Forget to add annotations, is to convert hours minutes, and then subtracting the minute difference, then formatted into hours

CodePudding user response:

 # include & lt; Stdio. H> 
Int main () {
Char ln [80].
Int H1, M1, H2, M2;
int d;

While (1) {
The rewind (stdin);
The fgets (ln, 80, stdin);
If (4==sscanf (ln, "% 2 d: % 2 d % 2 d: % 2 d", & amp; H1, & amp; M1, & amp; H2, & amp; M2)) {
If (0 & lt;=H1 & amp; & H1 & lt;=23
& & 0<=M1 & amp; & M1 & lt;=59
& & 0<=H2 & amp; & The H2 & lt;=23
& & 0<=M2 & amp; & M2 & lt;=59) break;
}
Printf (" H1, H2 M1, M2 format error. The Input again \ n ");
}
D=H2 * 60 + M2 * 60 + M1 (H1);
02 printf (" % d: % d \ n ", 60, d/d % 60);
return 0;
}
//input at 10:30 11:45
//output 1:15

CodePudding user response:

 printf (" % d: % 02 d \ n ", d/a 60, (60 d % & gt; 0)? % % d (60) : - (d) of 60); 

CodePudding user response:

The
quoted zhao teacher reply: 3/f
 # include & lt; Stdio. H> 
Int main () {
Char ln [80].
Int H1, M1, H2, M2;
int d;

While (1) {
The rewind (stdin);
The fgets (ln, 80, stdin);
If (4==sscanf (ln, "% 2 d: % 2 d % 2 d: % 2 d", & amp; H1, & amp; M1, & amp; H2, & amp; M2)) {
If (0 & lt;=H1 & amp; & H1 & lt;=23
& & 0<=M1 & amp; & M1 & lt;=59
& & 0<=H2 & amp; & The H2 & lt;=23
& & 0<=M2 & amp; & M2 & lt;=59) break;
}
Printf (" H1, H2 M1, M2 format error. The Input again \ n ");
}
D=H2 * 60 + M2 * 60 + M1 (H1);
02 printf (" % d: % d \ n ", 60, d/d % 60);
return 0;
}
//input at 10:30 11:45
//output 1:15


On the right, crab crab crab crab??

CodePudding user response:

refer to the second floor I keep was reply:
forget to add annotations, is to convert hours minutes, and then subtracting the minute difference, formatted into hours

Understand, crab crab??
  • Related