1樓:函小苼
1、首先,定義兩個整型變數,儲存計算出的每位二進位制數和二進位制位數的統計。
2、定義一個實型變數,儲存計算的十進位制小數。
3、輸入一個十進位制小數,儲存在變數d中。
4、do-while迴圈中,將十進位制小數乘以2。
5、取十進位制數的整數部分,儲存在變數b中。
6、輸出該位的二進位制數,同時將十進位制數的整數部分減掉。
7、執行程式,輸入任意一個十進位制小數,計算機就會輸出相應的二進位制小數。
2樓:數學與計算機程式設計
private sub command1_click()
me.caption = "二進位制轉化為十進位制"
if text1.text = "" then
msgbox "資料錯誤!", 64
text1.setfocus
me.caption = "進位制轉換"
exit sub
end if
if val(text1.text) = 0 then
label1.caption = 0
else
s = len(text1.text)
for i = 1 to s
if (val(mid(text1.text, i, 1)) <> 0 and val(mid(text1.text, i, 1)) <> 1) then
msgbox "資料錯誤!", 64
me.caption = "進位制轉換"
text1.setfocus
exit sub
end if
next i
for i = 1 to s
n = n + val(mid(text1.text, i, 1)) * 2 ^ (s - i)
next i
label1.caption = n
end if
text1.setfocus
end sub
private sub command2_click()
me.caption = "十進位制轉化為二進位制"
if text1.text = "" then
msgbox "資料錯誤!", 64
me.caption = "進位制轉換"
text1.setfocus
exit sub
end if
n = val(text1.text)
if n > 2147483647 then
msgbox "資料錯誤!", 64
me.caption = "進位制轉換"
text1.setfocus
exit sub
end if
if n = 0 then
label1.caption = 0
else
do while n > 0
r = n mod 2: n = n \ 2: b = cstr(r) + b
loop
label1.caption = b
end if
text1.setfocus
end sub
private sub command3_click()
text1.text = ""
label1.caption = ""
me.caption = "進位制轉換"
text1.setfocus
end sub
private sub text1_keypress(keyascii as integer)
if (keyascii < 48 or keyascii > 57) and keyascii <> 8 then
keyascii = 0
beep
end if
end sub
用vb程式設計序實現十進位制與二進位制之間的相互轉化。 50
3樓:匿名使用者
if instr(strf, textbox1.text, comparemethod.text) then
found = found + 1`匹配的話數目+1end if
next
label1.text = "found" & vbcr & found & vbcr & "object"
end if
end sub
4樓:匿名使用者
你要的是什麼vb版本的呢?
用vb程式設計:將二進位制轉化為十進位制。
5樓:匿名使用者
private sub form_load()msgbox bin_to_dec("11")end sub
public function bin_to_dec(byval bin as string) as long
dim i as long
for i = 1 to len(bin)bin_to_dec = bin_to_dec * 2 + val(mid(bin, i, 1))
next i
end function
6樓:匿名使用者
vb程式編寫:二進位制轉換為十進位制的函式
7樓:匿名使用者
示例附件中
private sub command1_click()text2 = bintodec(text1)end sub
private function bintodec(ejz as string) as long
bintodec = 0
dim w as long
for i = 0 to len(ejz) - 1if mid(ejz, len(ejz) - i, 1) = "1" then
bintodec = bintodec + 2 ^ ww = w + 1
elseif mid(ejz, len(ejz) - i, 1) = "0" then
w = w + 1
end if
next
end function
8樓:匿名使用者
private sub form_load()debug.print b2d("1101")end sub
private function b2d(src as string) as integer
dim i as integer
dim out as integer
out = 0
for i = 1 to len(src)out = out * 2 + cint(mid(src, i, 1))
next
b2d = out
end function
“求1到10的階乘之和”用vb怎麼程式設計序
先寫一個求階乘的函式 private function factorial byval n as integer as long dim i as integer,l as longl 1 for i 1 to n l l i next factorial l end function 新增一個按鈕...
用vb程式設計,窗體中有命令按鈕。程式執行時,單擊“顯示”命令按鈕,在窗體上顯示1000以為個位數
均勻排列 如下 private sub command1 click dim i as integer dim j as integer dim k as integer dim a 5 as string i 5 k 0 for j 1 to 1000 i i 5 if i mod 3 0 and...
求高手解決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 ...