知識社群登入
位置: AutoCAD開放式教學 > 討論區 > 討論
(x + 1) < x
1樓
//
#if 0

x= 2147483647, y= (x + 1)= -2147483648, dt= 10.937
Press any key to continue

#endif
// ----------------------------------------------

// file: inc-01.h

#include <stdio.h>
#include <math.h>
#include <process.h>
#include <conio.h>
#include <sys/timeb.h>
#include <time.h>

// #include "sj-01.h"

// skip(-3);
void skip(int no)
{
// limits no in 1 .. 20
if ((no >= 1) && (no <= 20)) {// no is OK
int i;
for (i=1;i<=no;i++) {
printf("\n");
}
}
else {// no is invalid!
printf("\n");
}
}// end of skip()
// ----------------------------------------------

//   pause();
void pause(void)
{
// remove type- ahead
while (kbhit()) {
getch();
}
// ----------------------------------------------
printf(" *** Press [Esc] key for Stop! or other key for Continue...");
do {
// wait for KeyPress
} while(!_kbhit());
int ch1= getch();
printf("\n");
// ----------------------------------------------
if (ch1==0x1b) {// [Esc] key be pressed
exit(1);
}
// remove extra key Strok
while (kbhit()) {
getch();
}
}// end of pause()
// ----------------------------------------------


// #include "sj-02.h"

// time1(&t1);
void time1(int *t1)
{
struct _timeb timebuffer;
int sec, ms;
_ftime( &timebuffer );
sec= timebuffer.time;
ms= timebuffer.millitm;
sec%= (24L*86400);
(*t1)= sec*1000 + ms;
}// end of time1()
// ----------------------------------------------

//   time2(t1, &dt);
void time2(int t1, double *dt)
{
int t2;
time1(&t2);
(*dt)= (t2 - t1)/1000.0;
// (*dt) >= 0.0
if ((*dt) < 0.0) {
(*dt)+= (24L*86400);
}
}// end of time2()
// ----------------------------------------------


// ----------------------------------------------



int main()
{
//
int x, y, t1;
double dt;
x= 10;
y= x + 1;
// y > x
time1(&t1);
while (y > x) {
// x++;
y= (++x) + 1;
}
time2(t1, &dt);
printf("x= %d, y= (x + 1)= %d, dt= %.3lf \n", x, y, dt);
return(0);
}// end of main()