1樓:匿名使用者
private sub command1_click()dim pi as single
dim r as single
dim l as single
dim a as single
pi = 3.141592654
r = inputbox("輸入半徑r=")l = pi * r
a = r ^ 2 * pi / 4
print "周長=", l
print "面積=", a
end sub
2樓:匿名使用者
private sub cmdok_click()dim pi as double
pi = 3.14
if isnumeric(trim(txtr.text)) = false then
msgbox "請輸入乙個合法的數"
txtr.text = ""
txtr.setfocus
exit sub
end if
txtg.text = formatnumber((2 * pi * val(txtr.text)), 2)
txta.text = formatnumber(pi * val(txtr.text) * val(txtr.text), 2)
end sub
private sub form_load()txtr.text = ""
txtg.text = ""
txta.text = ""
me.show
txtr.setfocus
end sub
-----------------
txtr:半徑 txtg:周長 txta: 面積
vb 輸入半徑,計算圓周長和圓面積
3樓:匿名使用者
執行通過,希望對你有幫助。
private sub command1_click()dim r as double
r = val(text1.text)
c = 2 * 3.14 * r
s = 3.14 * r * r
print "周長c="; c; "面積s="; send sub
private sub form_load()me.show
text1.text = ""
msgbox "請輸入要計算的圓的半徑"
text1.setfocus
end sub
輸入半徑,用vb編寫計算圓面積和圓周長的程式
4樓:殺神一刀斬
private sub label2_click()const pi = 3.14159
dim r as single, i as single, s as single
r = inputbox("請輸入半徑:", "輸入半徑")i = 2 * pi * r
s = pi * r ^ 2
label2 = label2 & r
label3 = label3 + str(i)label4 = label4 + str(s)end sub
當然你要有四個label控制項,第乙個可以隨便設定,例如寫成「計算圓的周長與面積」
5樓:匿名使用者
private sub command1_click()dim bj as single
dim zz as single
dim mj as single
bj = csng(text1.text)if bj <= 0 then
msgbox "你的輸入有誤"
exit sub
end if
mj = 3.1415 * bj * bjmsgbox "面積是" & format(mj, "0.00")end sub
private sub command2_click()dim bj as single
dim zz as single
dim mj as single
bj = csng(text1.text)if bj <= 0 then
msgbox "你的輸入有誤"
exit sub
end if
zz = 2 * bj * 3.1415
msgbox "周長是" & format(zz, "0.00")end sub
vb作業 作業:輸入圓的半徑,計算圓面積和圓周長。計算結果資料型別為單精度型。
6樓:匿名使用者
①方法1:
private sub command1_click()dim p as single
dim s as single
dim r as single
p = 3.1415 '定義pai的值r = val(text1)
s = p * r ^ 2 '面積公式c = 2 * p * r '周長公式label2.caption = c '標籤2輸出周長結果text2 = s '文字框2輸出面積結果end sub
②方法2
private sub command1_click()dim p as single
dim s as single
dim r as single
p = 3.1415 '定義pai的值r = inputbox("請輸入乙個圓的半徑", "輸入", 0) '獲取輸入值
s = p * r ^ 2 '面積公式c = 2 * p * r '周長公式msgbox ("圓的面積為:" & s & "圓的周長為:" & c) '輸出結果
end sub
vb:輸入半徑,計算圓周長和圓面積。執行介面如下
7樓:匿名使用者
private sub command1_click()if not isnumeric(text1) thenmsgbox "***"
text1.setfocus
exit sub
end if
dim r as single
r = val(text1.text)
text2.text = 3.14 * r * rend sub
private sub command2_click()if not isnumeric(text2) thenmsgbox "***"
text2.setfocus
exit sub
end if
dim r as single
r = val(text1.text)
text3.text = 2 * 3.14 * rend sub
8樓:
不了解isnumeric,寫了個函式
private sub command1_click()dim r as single
if isval(trim(text1.text)) thenr = val(text1.text)
text2.text = 3.14 * r * relse
msgbox "input error"
text1.setfocus
end if
end sub
private sub command2_click()dim r as single
if isval(trim(text1.text)) thenr = val(text1.text)
text3.text = 2 * 3.14 * relse
msgbox "input error"
text1.setfocus
end if
end sub
function isval(str as string) as boolean
dim strcmp
dim i as integer
dim strtemp as stringstrcmp = "0123456789."
isval = true
for i = 1 to len(str)strtemp = mid(str, i, 1)if mid(str, i, 1) = "." and mid(str, i + 1, 1) = "" then
isval = false
exit function
end if
if instr(strcmp, strtemp) = 0 thenisval = false
exit function
end if
next
dim str1() as string
str1 = split(str)
if ubound(str1) > 0 thenisval = false
exit function
end if
end function
vb輸入半徑,計算圓周長和圓面積。
9樓:匿名使用者
執行通過,希望對你有幫助。
private sub command1_click()dim r as double
r = val(text1.text)
c = 2 * 3.14 * r
s = 3.14 * r * r
print "周長c="; c; "面積s="; send sub
private sub form_load()me.show
text1.text = ""
msgbox "請輸入要計算的圓的半徑"
text1.setfocus
end sub
10樓:戰瑋鄂浩歌
dim r as single
dim c as single
dim s as single
if isnumeric(text1.text) = true then
r = text1.text
c = formatnumber(2 * 3.14 * r, 2)s = formatnumber(3.14 * r ^ 2, 2)print "圓的周長、面積分別為:
", c, selse
msgbox "你輸入的數錯誤!"
text1.setfocus
text1.selstart = 0
text1.sellength = len(text1.text)end if
想象著寫的,這邊沒vb,自己除錯下吧。
程式設計實現半徑為2的圓的面積和周長。c語言
include define pi 3.1415926 main ajuagptwndnx 程式設計從鍵盤輸入圓的半徑r,計算並輸出圓的周長和面積.用c語言編寫 謝了 方法 include define pi 3.14 int main 一 圓的面積公式 圓的面積計算公式 或圓的面積求直徑 二 計算...
C 程式設計求助編寫基於物件的程式 輸入半徑,計算圓的周長和面積並輸出
include iostream define pi 3.1415962 using namespace std class circle circle double x 建構函式double length double area main include define pi 3.14 class ...
用VB算圓的面積用文字框輸入半徑點選按鈕以後再另文字框得出結果
在form1中依次新增2個文字框和1個按鈕。然後輸入如下 private sub command1 click dim r as double if isnumeric text1.text thenr val text1.text if r 0 then text2.text str 3.1415...