早教吧 育儿知识 作业答案 考试题库 百科 知识分享

1只公鸡5块钱,1只母鸡3块钱,3只小鸡1块钱,100块钱买100只鸡,那公鸡,母鸡,小鸡各多少个,用VB语言解

题目详情
1只公鸡5块钱,1只母鸡3块钱,3只小鸡1块钱,100块钱买100只鸡,那公鸡,母鸡,小鸡各多少个,用VB语言解
▼优质解答
答案和解析
dim num1,num2,total
dim i,j
dim result
dim isEnd
isEnd = false
for i = 1 to 100
num1 = i
for j = 1 to 100 - i - 1
num2 = j
total = num1 * 5 + num2 * 3 + (100 - num1 - num2)/3
if total = 100 then
result = "公鸡有" & num1 & "只,母鸡有" & num2 & "只,小鸡有" & (100-num1-num2) & "只."
isEnd = true
exit for
end if
next
if isEnd then
exit for
end if
next
看了 1只公鸡5块钱,1只母鸡3块...的网友还看了以下: