PB入门教程A
PowerBASIC的示例代码
我们根据这期所学的知识来做个示例:
问题:百元买鸡问题,假设小鸡每只五角,公鸡每只三元,现在有一百元买一百只鸡,编写程序列出所有的购买方案
我们做了如下回答:
#COMPILE EXE #DIM ALL
#include "Win32api.inc" function Calculate() as long Dim x as INTEGER
dim y as INTEGER dim z as INTEGER for x = 0 to 100
for y = 0 to 100
for z = 0 to 100
if (x + y + z = 100) and ((3*x + 2*y + 0.5*z) = 100) THEN
msgbox "母鸡:" + str$(x) + " 公鸡:" + str$(y) + " 小鸡:" + str$(z) , 32,"
END IF
可能的购买方案"
NEXT
NEXT
NEXT
END FUNCTION
FUNCTION PBMAIN () AS LONG
Call Calculate() END FUNCTION