
398
|
第
18
章
示例
int people, apples;
div_t share;
for ( apples = -3 ; apples < 6 ; apples += 3 )
{
if ( apples == 0 )
continue; // 0
作为被除数,不用计算
for ( people = -2 ; people < 4 ; people += 2 )
{
if ( people == 0 )
continue; //
无须担心
0
作为除数
share =
div
( apples, people );
printf( "If there are %+i of us and %+i apples, "
"we each get %+i with %+i left over.\n",
people, apples, share.quot, share.rem );
}
}
上述程序代码将产生以下输出,其中,任何非零的余数与被除数有相同的符号:
If there are -2 of us and -3 apples, we each get +1 with -1 left over.
If there are +2 of us and -3 apples, we each get -1 with -1 left over.
If there are -2 of us and +3 apples, ...