• 主页

# VB循环比较的问题

suncumt 2008-01-17 06:36:11

dim a as integer,b as integer,c as integer,d as integer
dim x as double
for a=20 to 150
for b=20 to 150
for c=20 to 150
for d=20 to 150
if (a*b)/(c*d)<=x then
text1.text=a
text2.text=b
text3.text=c
text4.text=d
end if
next d
next c
next b
next a

...全文
250 点赞 收藏 14

14 条回复

suncumt 2008-01-22

print a,b,c,d

text1.text=a
text2.text=b
text3.text=c
text4.text=d

suncumt 2008-01-21

z_wenqian 2008-01-17

z_wenqian 2008-01-17
dim a as integer,b as integer,c as integer
dim x as double
for a=20 to 150
for b=20 to 15-a
for c=20 to 150
for d=20 to 150-a -b
text1.text=a
text2.text=b
text3.text=c
text4.text=150-a-b-c
next c
next b
next a

of123 2008-01-17

1 a * b 的乘积的定义域是 20 的平方至 150 的平方，做这个循环。也就是先取得积 m 。
2 n = m \ x 就是 c * d 的积。如果满足 20 ^2 <= n <= 150 则，这组 m, n 就是符合条件的积。
3 把 m 和 n 分解成 2 * b, c * d。由于 a 和 b, 以及 c 和 d 是可互换的，解出一组足矣。所以最大循环至 m 平方根和 n 的平方根。

suncumt 2008-01-17

suncumt 2008-01-17

suncumt 2008-01-17

X为任意一个小数

clear_zero 2008-01-17

of123 2008-01-17
a 与 b, c 与 d 是完全对等的，不必从头到尾计算一遍。

dim a as integer,b as integer,c as integer,d as integer
dim x as double

dim m as long, n as long, tmp as long
for m = 20 ^2 to 150 ^ 2
n = m \ x
if n > 150 ^ 2 then exit for
if n > 20 ^ 2 then
debug.print "following (a * b) / (c * d) < " & x
tmp = m ^ 0.5
for a = tmp to 20 step -1
b = m \ a
if b > 150 exit for
if b >= 20 then debug.print "a = " & a, "b = " & b
next a
debug.print ""
tmp = n ^ 0.5
for c = tmp to 20 step -1
d = n \ c
if d > 150 exit for
if d >= 20 then debug.print "c = " & c, "d = " & d
next a
debug.print ""
end if
next m

suncumt 2008-01-17

of123 2008-01-17
dim a as integer,b as integer,c as integer,d as integer
dim x as double
for a=20 to 150
for b=20 to 150
for c=150 to 20 step -1
for d=150 to 20 step -1
if (a*b)/(c*d) <=x then
text1.text=a
text2.text=b
text3.text=c
text4.text=d
end if
next d
next c
next b
next a

VB基础类

7451

VB 基础类