Answer
问题及解答
1
fun f3()
{
var i, j, m, n, x;
for (i = 1; i < 168 / 2 + 1; i = i + 1) // clox 中不支持 i++ 要替换为 i=i+1
{
if (168 @ i == 0) // 我们使用 @ 代表模运算, 即 C 语言中的 %
{
j = 168 / i;
if ( i > j and (i + j) @ 2 == 0 and (i - j) @ 2 == 0) // and 代表 C 语言中的 &&
{
m = (i + j) / 2;
n = (i - j) / 2;
x = n * n - 100;
println x, " + 100 = ", n, " * ", n; //printf ("%d + 100 = %d * %d\n", x, n, n);
println x, " + 268 = ", m, " * ", m; //printf ("%d + 268 = %d * %d\n", x, m, m);
}
}
}
}
将上述代码保存至 code\exer3.sy, 然后执行.
>> :mode clox
> load(code\exer3.sy)
> f3();
-99 + 100 = 1 * 1
-99 + 268 = 13 * 13
21 + 100 = 11 * 11
21 + 268 = 17 * 17
261 + 100 = 19 * 19
261 + 268 = 23 * 23
1581 + 100 = 41 * 41
1581 + 268 = 43 * 43
>