1樓:
dim p as integer, q as integer
dim i as integer, j as integer,n as integer
'有一根長度為546米的鋼材料,要將它擷取成兩種規格a、b的長度分別為19米和28米的短料,
'每種至少1段,問分隔成a,b各多少段後,剩餘的殘料r最少?程式設計解決此計算問題。
for i = 1 to int(546 / 19)
' for j = 2 to int(546 / 28)
if (546 - 19 * i) mod 28 < (546 - 19 * (i - 1)) mod 28 then
p = i: q = (546 - 19 * i) / 28
end if
n=546-19*p-28*q
'next
next
print p, q,n '輸出 27 1 5
2樓:匿名使用者
'最優是 19米14,28米10,剩餘0 注意加個text1,設為多行
private sub command1_click()
dim tmp as variant
dim tmp1 as single, tmp2 as single, s_tp as string
dim t*** as variant
dim s1 as string, ss as string, l_tp as single
dim i as long, l as long, x as long, k1 as long, k2 as long, k3 as long, k4 as long, kk as long
kk = 546
k1 = 19
k2 = 28
k3 = kk \ k1k4 = kk \ k2
for i = 1 to k3
for l = 1 to k4
l_tp = i * k1 + l * k2
if l_tp <= kk then
s1 = i & "," & l & "," & kk - l_tp
ss = ss & "*" & s1
end if
next
next
tmp = split(ss, "*")
for i = 1 to ubound(tmp)
for x = i + 1 to ubound(tmp)
tmp1 = mid(tmp(x), instrrev(tmp(x), ",") + 1, 3)
tmp2 = mid(tmp(i), instrrev(tmp(i), ",") + 1, 3)
if tmp1 > tmp2 then
s_tp = tmp(i)
tmp(i) = tmp(x)
tmp(x) = s_tp
end if
next
next
print tmp(ubound(tmp))
ss = k1 & "米," & k2 & "米," & "剩餘"
for i = ubound(tmp) to 0 step -1
ss = ss & vbcrlf & tmp(i)
' print tmp(i)
next
text1.text = ss
msgbox "利用率最高的方法是" & tmp(ubound(tmp))
end sub
使用vb進行程式設計有哪些步驟使用VB進行程式設計有哪些步驟
視覺化程式設計一般有一下步驟 設計程式介面 編寫程式 除錯 執行程式 物件導向的程式設計以物件為中心,以事件為過程執行的起點 例題 設計一個簡易的打字測試程式,單擊 開始 按鈕,計時開始,輸入字元 單擊 結束 按鈕,程式輸出打字速度。1 啟動vb,新建一個vb標準exe工程。單擊工具箱中的文字框控制...
vb程式設計計算,VB程式設計計算 1 2
private sub command1 click dim i as integer,j as integerdim l as long,h as longfor i 1 to 10 h 1 for j 1 to i h h j next l l h next print l end sub pr...
vb程式設計教程答案,vb程式設計教程答案
option explicit private sub command1 click dim a as integer dim i,j,n redim a 9,9 for i 1 to 8 print tab 25 i 2 for j 1 to i a i,1 1 a i,i 1 a i 1,j 1...