调不通,求解释
编译环境VC6通过,TC2.0出现奇怪问题。表现在输入较大的数时,比如999999999(9个9)
我觉得不该溢出的。结果却出乎我意料。
// min_sec.c -- converts seconds to minutes and seconds
#include <stdio.h>
#include <limits.h>
#define SEC_PER_MIN 60
#define SEC_PER_HOUR 3600
int main(void)
{
int min, leftsec,hour;
long sec;
printf("%d,%ld\n",INT_MAX,LONG_MAX);
printf("Convert seconds to minutes and seconds!\n");
printf("Enter the number of seconds (<=0 to quit):\n");
scanf("%d", &sec);
while (sec > 0)
{
hour = sec / SEC_PER_HOUR;
printf("hour=%d\n",hour);
leftsec = sec % SEC_PER_HOUR;
printf("leftsec=%d\n",leftsec);
min = leftsec/SEC_PER_MIN;
printf("min=%d\n",min);
leftsec=leftsec%SEC_PER_MIN;
printf("leftsec=%d\n",leftsec);
printf("%ld seconds is %d hour,%d minutes, %d seconds.\n", sec,
hour,min, leftsec);
printf("Enter next value (<=0 to quit):\n");
scanf("%d", &sec);
}
printf("Done!\n");
return 0;
}