主题:请各位大虾帮忙
小精灵LS
[专家分:580] 发布于 2007-08-13 10:32:00
有30个男人女人和小孩同在一家饭馆进餐,共花了五十先令,其中男宾3先令,女宾2先令,小孩1先令.试编程求出男人女人小孩各多少人?
回复列表 (共4个回复)
沙发
小精灵1号 [专家分:1040] 发布于 2007-08-13 10:43:00
CLS
FOR a = 1 TO 50 \ 3
FOR b = 1 TO 50 \ 2
FOR c = 1 TO 28
IF a + b + c = 30 AND 3 * a + 2 * b + c = 50 THEN PRINT a; b; c: s = s + 1
NEXT c, b, a
PRINT "S="; s
END
板凳
我的电脑 [专家分:990] 发布于 2007-08-13 11:12:00
CLS
FOR a = 1 TO 50 \ 3
FOR b = 1 TO 50 \ 2
FOR c = 1 TO 28
IF a + b + c = 30 AND 3 * a + 2 * b + c = 50 THEN PRINT a; b; c: s = s + 1
NEXT c, b, a
PRINT "S="; s
END
3 楼
wzc1996 [专家分:1680] 发布于 2007-08-13 12:07:00
CLS
PRINT "MAN", "WOMAN", " CHILDREN"
FOR M= 1 TO INT(50 / 3)
FOR W= 1 TO INT(50 / 2)
C = 30 - M - W
IF M + W + C = 30 AND M * 3 + W * 2 + C = 50 THEN PRINT M, W, C: S = S + 1
NEXT W
NEXT M
PRINT "ZONGJI:"; S
END
比小精灵1号和我的电脑打印美观,而且少一个FOR循环,速度更快!
4 楼
hxy_anhui [专家分:320] 发布于 2009-01-29 22:23:00
CLS
FOR A = 1 TO 50 \ 3
FOR B = 1 TO 50 \ 2
C = 30 - A - B
IF 3 * A + 2 * B + C = 50 THEN PRINT A; B; C : S = S + 1
NEXT B
NEXT A
PRINT "S="; S
END
我来回复