1樓:匿名使用者
private sub command1_click()
'第1題,需要在窗體中加按鈕command1
dim i as integer, j as integer, ka as integer, kc as integer
dim b as boolean
dim a() as integer, c() as integer
for i = 1 to 100
if i = 1 then b = false else b = true
for j = 1 to i
if i mod j = 0 and j <> i and i <> 1 then b = false
next
if b then
if i mod 2 = 0 then
ka = ka + 1
redim preserve a(1 to ka)
a(ka) = i
else
kc = kc + 1
redim preserve c(1 to kc)
c(kc) = i
end if
end if
next
print "1~100內的偶素數"
for i = 1 to ka
print a(ka)
next
print "1~100內的奇素數"
for i = 1 to kc
print c(kc)
next
end sub
private sub command2_click()
'第2題,需要在窗體中加按鈕command2
dim i as integer, j as integer, k as double
print "1~100內的勾股數"
for i = 1 to 100
for j = i + 1 to 100
k = sqr(i * i + j * j)
if k <= 100 and k - int(k) = 0 then print i & " " & j & " " & k
next
next
end sub
private sub command3_click()
'第3題,需要在窗體中加按鈕command3和文字框text1、text2
'文字框text1中為輸入,文字框text2中為輸出
dim sta as string, stb as string
dim i as long, j as long
sta = text1.text
j = len(sta)
stb = ""
for i = j to 1 step -1
stb = stb & mid(sta, i, 1)
next
text2.text = stb
end sub
private sub command4_click()
'第4題,需要在窗體中加按鈕command4和文字框text3、text4、text5
'文字框text3中為係數a輸入,文字框text4中為係數b輸入,文字框text5中為係數c輸入
dim a as double, b as double, c as double, d as double, x1 as double, x2 as double
if not isnumeric(text3.text) then
msgbox "輸入的係數a不是有效數字", , "錯誤"
exit sub
end if
if not isnumeric(text4.text) then
msgbox "輸入的係數b不是有效數字", , "錯誤"
exit sub
end if
if not isnumeric(text5.text) then
msgbox "輸入的係數c不是有效數字", , "錯誤"
exit sub
end if
a = val(text3.text)
b = val(text4.text)
c = val(text5.text)
d = b * b - 4 * a * c
if d < 0 then
msgbox "無有理數解", , ""
exit sub
end if
x1 = (-b + d) / (2 * a)
x2 = (-b - d) / (2 * a)
print "x的第一個解"
print format(x1, "general number")
print "x的第二個解"
print format(x2, "general number")
end sub
private sub command5_click()
'第5題,需要在窗體中加按鈕command5
dim a(1 to 10, 1 to 10) as double, b as double
dim i as integer, j as integer, k as integer, t as integer
for i = 1 to 10
for j = 1 to 10
a(i, j) = val(inputbox("請輸入第" & i & "名選手的第" & j & "個得分", "輸入"))
next
b = a(i, 1)
k = 1
for j = 2 to 10
if b < a(i, j) then
b = a(i, j)
k = j
end if
next
b = a(i, 1)
t = 1
for j = 2 to 10
if b > a(i, j) then
b = a(i, j)
t = j
end if
next
if k = t then
a(i, 1) = 0
a(i, 2) = 0
else
a(i, k) = 0
a(i, t) = 0
end if
b = 0
for j = 1 to 10
b = b + a(i, j)
next
b = b / 8
msgbox "第" & i & "名選手的平均分是" & b, , "輸出"
next
end sub
2樓:匿名使用者
...素數除了2都是奇數
3樓:好幾碗粥
...素數除了2都是奇數
回答者: murderor - 江湖少俠 七級 2009-6-17 10:21
vb程式設計高手進,高分求助
窗體 請到我的空間提取 msgbox 除數為零,請檢查輸入的資料是否正確!vbcritical vbokonly,輸入錯誤 end if end if end sub private sub mnuclear click text1.text text2.text text3.text label1...
求高手解決vb程式試題,vb程式設計選擇題 求高手解答 !
選擇題 1.c 2.a 3.a 填空題 1,連字元 2,rgb 255,0,0 3,34,3 分析題 b改錯題 1,2.dim n as integer n 120 if n mod 2 0 then print 它是偶數 endif 選擇題 1,c2,c 3,a4,d 5,a6,a 7,a8,b ...
pascal語言程式設計題求高手呀追加跪求進來看一看
答案不唯一,abc ab ac都是答案 vari1,i2,i3,j longint begin for i1 1 to 2 do for i2 1 to 2 do for i3 1 to 2 do if ord i1 1 ord i1 1 ord i3 2 and i2 2 2 then begin...