判斷整除並求和

2021-06-06 05:22:22 字數 1278 閱讀 2390

private sub command1_click()

dim m as integer, n as integer, d asinteger

dim s as long '儲存結果

m = val(text1.text)

n = val(text2.text)

d = val(text3.text)

s = 0

sum m, n, d, s

label4.caption = m & "到" & n & "之間能被" & d & "整除的數之和是" & s

end sub

private sub command2_click()

endend sub

'sub過程:求m到n之間能被d整除的數之和

public sub sum(x as integer, y as integer,z as integer, w as long)

dim i as integer

'若x>y,交換

if x > y then

t = x: x = y: y = t

end if

for i = x to y

if i mod z = 0 then

w = w + i

end if

next i

end sub

private sub text1_keypress(keyascii asinteger) '文字框鍵盤事件過程

'若按鍵非數字鍵或回刪鍵,取消按鍵

if not isnumeric(chr(keyascii)) andkeyascii <> 8 then

keyascii = 0

end if

end sub

private sub text2_keypress(keyascii asinteger) '文字框鍵盤事件過程

'若按鍵非數字鍵或回刪鍵,取消按鍵

if not isnumeric(chr(keyascii)) andkeyascii <> 8 then

keyascii = 0

end if

end sub

private sub text3_keypress(keyascii asinteger) '文字框鍵盤事件過程

'若按鍵非數字鍵或回刪鍵,取消按鍵

if not isnumeric(chr(keyascii)) andkeyascii <> 8 then

keyascii = 0

end if

end sub

VB判斷整除並整除

private sub command1 click dim m as integer,n as integer,d as integer dim s as long 儲存結果 m val text1.text n val text2.text d val text3.text s 0 sum m,...

1195 判斷整除

題目描述 乙個給定的正整數序列,在每個數之前都插入 號或 號後計算它們的和。比如序列 1 2 4共有8種可能的序列 1 2 4 7 1 2 4 1 1 2 4 3 1 2 4 5 1 2 4 5 1 2 4 3 1 2 4 1 1 2 4 7 所有結果中至少有乙個可被整數k整除,我們則稱此正整數序列...

1195 判斷整除

1195 判斷整除 時間限制 1000 ms 記憶體限制 65536 kb 題目描述 乙個給定的正整數序列,在每個數之前都插入 號或 號後計算它們的和。比如序列 1 2 4共有8種可能的序列 1 2 4 7 1 2 4 1 1 2 4 3 1 2 4 5 1 2 4 5 1 2 4 3 1 2 4 ...