1樓:匿名使用者
新建工程,1個文字框和1個按鈕
text1用來錄入資料, 因為是任意個數,用很多文字框是不方便的,程式設計是使用","來分隔數字,你可以輸入任意多個數字,然後按鈕command1後,就可以顯示總和及平均值.
private sub command1_click()
if len(text1) = 0 then exit sub
if instr(text1, ",") < 2 then exit sub
dim a, sumn%, i%, j%
a = split(text1, ",")
for i = 0 to ubound(a)
if isnumeric(val(a(i))) then '防止有非數字的情況發生,做一下校驗
sumn = sumn + val(a(i))
j = j + 1
end if
next
print "總和為:" & sumn
print "平均數為:" & sumn / (ubound(a) + 1)
end sub
2樓:旅初彤
你說一下是求多少個數的平均數嗎?
vb 編寫程式 輸入3個數 求和和平均數
用vb程式計算三個數的平均值 **要簡單易懂的,本人菜鳥
3樓:苦寒
private sub command1_click() '計算平均分
dim a as single, b as single, c as single, d as single
a = val(text1.text)
b = val(text2.text)
c = val(text3.text)
d = (a + b + c) / 3
text4.text = d
end sub
private sub command2_click() 『清除
text1.tex = ""
text2.tex = ""
text3.tex = ""
text4.tex = ""
end sub
private sub command3_click() 』退出endend sub
4樓:匿名使用者
private sub command1_click()a = val(text1.text)
b = val(text2.text)
c = val(text3.text)
d = (a + b + c) / 3
print d
end sub
vb程式設計:任意輸入10個數,求平均值,求**
在vb中計算平均值
5樓:孤本輕狂
private function dd(a() as double, n as integer, b() as double, m as integer)
for i = 3 to n - 4
b(i - 3) = a(i)
next
m = n - 6
end function
'排序函式 從大到小
private function px(a() as double, b as integer)
dim max as double
for i = 0 to b - 2
for j = i + 1 to b - 1
if a(i) < a(j) then
max = a(j)
a(j) = a(i)
a(i) = max
end if
next
next
end function
private sub command1_click()
dim inttemp(16) as double
dim intdata(10) as double
dim n as integer
dim sum as double
dim l
for i = 1 to 16
randomize
inttemp(i - 1) = format((rnd * 10 + 40), "0.00")
text1(i).text = cstr(inttemp(i - 1))
next i
call px(inttemp, 16)
l = dd(inttemp(), 16, intdata(), n)
for i = 0 to n - 1
sum = sum + intdata(i)
print cstr(intdata(i))
next
text1(17).text = sum / 10
end sub
private sub form_load()
form1.height = 9500
for i = 1 to 17
load text1(i)
text1(i).visible = true
text1(i).left = text1(0).left
text1(i).top = text1(i - 1).top + 450
next
end sub
6樓:
這麼複雜的問題也就10分,唉
如何用vb求數的平均數,幾何平均數和平方平均數?分開寫,謝謝。(只要入門的程式就好,高階的不要)
dim a as single dim b as single dim c as single dim x as single text1.text a text.2text b text3.text c label1.caption x 1 算術平均數 x a b c 3 2 幾何平均數 x a ...
用VB求數的最大數,用VB求五個數的最大數
function maxnum a,b,c,d,e as long dim arr 0 to 5 dim i as long arr 1 a arr 2 b arr 3 c arr 4 d arr 5 e for i 1 to ubound arr if maxnum arr i thenmaxnu...
第三題和第四題,用三個數的均值不等式計算
因為 1 2 x 1 2 x 2 x 2而,1 2 x 1 2 x 2 x 3 1 2 x 1 2 x 2 x 1 3 即,2 3 1 2 x 1 2 x 2 x 1 3 1 2 x 1 2 x 2 x 1 3 2 3 1 2 x 1 2 x 2 x 2 3 8 27x 4 2 x 32 27 當且...