主题:x^2和x*x的不同
以下两个程序,结果不同:
1.这个在qbasic1.1/qb4.5/qb7.1/vbdos(vbdos的结果比较满意)下运行结果也不同
CLS
INPUT r
a = INT(SQR(r))
FOR x = 0 TO a
FOR y = 0 TO a
FOR z = 0 TO a
IF x ^ 2 + y ^ 2 + z ^ 2 = r THEN n = n + 1: PRINT x; y; z; r
NEXT z, y, x
PRINT n
END
----------------------------------------
2.这个的结果比较统一
CLS
INPUT r
a = INT(SQR(r))
FOR x = 0 TO a
FOR y = 0 TO a
FOR z = 0 TO a
IF x * x + y * y + z * z = r THEN n = n + 1: PRINT x; y; z; r
NEXT z, y, x
PRINT n
END
----------------------------------------
3.由第1个修改后,运行结果同2,输出正常
CLS
INPUT r
a = INT(SQR(r))
FOR x = 0 TO a
FOR y = 0 TO a
FOR z = 0 TO a
m = x ^ 2 + y ^ 2 + z ^ 2
IF m = r THEN n = n + 1: PRINT x; y; z; r
NEXT z, y, x
PRINT n
END
1.这个在qbasic1.1/qb4.5/qb7.1/vbdos(vbdos的结果比较满意)下运行结果也不同
CLS
INPUT r
a = INT(SQR(r))
FOR x = 0 TO a
FOR y = 0 TO a
FOR z = 0 TO a
IF x ^ 2 + y ^ 2 + z ^ 2 = r THEN n = n + 1: PRINT x; y; z; r
NEXT z, y, x
PRINT n
END
----------------------------------------
2.这个的结果比较统一
CLS
INPUT r
a = INT(SQR(r))
FOR x = 0 TO a
FOR y = 0 TO a
FOR z = 0 TO a
IF x * x + y * y + z * z = r THEN n = n + 1: PRINT x; y; z; r
NEXT z, y, x
PRINT n
END
----------------------------------------
3.由第1个修改后,运行结果同2,输出正常
CLS
INPUT r
a = INT(SQR(r))
FOR x = 0 TO a
FOR y = 0 TO a
FOR z = 0 TO a
m = x ^ 2 + y ^ 2 + z ^ 2
IF m = r THEN n = n + 1: PRINT x; y; z; r
NEXT z, y, x
PRINT n
END