设计一个算法,求所有这样的三位数这些三位数等于它各位数字的立方和.用Qbasic程序求解设计一个算法,求所有这样的三位数这些三位数等于它各位数字的立方和.n=100x=1y=0i=0Do IF n=x^3+y^3+i^3 THENPRINT nEND IFn=n+1i=i+1IF i>9 THENi=0y=y+1END IF IF y>9 THENy=0x=x+1END IFLOOP UNTIL n>=1000END
设计一个算法,求所有这样的三位数这些三位数等于它各位数字的立方和.用Qbasic程序求解
设计一个算法,求所有这样的三位数这些三位数等于它各位数字的立方和.
n=100
x=1
y=0
i=0
Do
IF n=x^3+y^3+i^3 THEN
PRINT n
END IF
n=n+1
i=i+1
IF i>9 THEN
i=0
y=y+1
END IF
IF y>9 THEN
y=0
x=x+1
END IF
LOOP UNTIL n>=1000
END
cls
dim a(3)
for i=100 to 999
l=i
s=0
do
s=s+1
a(s)=l mod 10
l=l\10
loop until l=0
w=0
for j=1 to 3
w=w+a(j)^3
next j
if w=i then print i
next i
end
简单
cls
n = 0
for a = 1 to 9
for b = 0 to 9
for c = 0 to 9
x= a ^ 3 + b ^ 3 + c ^ 3
y= a * 100 + b * 10 + c
if x = y then n = n + 1 : print n, x
next c, b, a
OK了
你说的是 水仙花数 吗
n=100
x=1
y=0
i=0
Do
IF n=x^3+y^3+i^3 THEN
PRINT n
END IF
n=n+1
i=i+1
IF i>9 THEN
i=0
y=y+1
END IF
IF y>9 THEN
y=0
x=x+1
END IF
LOOP UNTIL n>=1000
END
水仙花数或者叫阿姆斯特朗数
CLS
DIM ams(15000)
DIM e(1000)
DO
INPUT x,y "输入一个X,y的范围,例 如你要算100-1000以内的阿母斯数,就输入100,1000
n = 0
FOR i = x TO y
CLS
PRINT (i / y) * 100; "%"
c$ = STR$(i)
a = LEN(LTRIM$((c$)))
FOR j = 1 TO a
d = VAL(MID$(LTRIM$(c$), j, 1))
e(j) = 1
FOR k = 1 TO a
e(j) = d * e(j)
NEXT k
NEXT j
f = 0
FOR j = 1 TO a
f = e(j) + f
NEXT j
IF f = i THEN n = n + 1: ams(n) = i
NEXT i
CLS
FOR i = 1 TO n
IF ams(i) 0 THEN PRINT ams(i); ",";
NEXT i
PRINT
PRINT "do you want go on Y/N"
INPUT t$
LOOP UNTIL t$ "y" OR t$ "Y"