1樓:數學與計算機程式設計
private sub command1_click()dim m as long
m = inputbox("請輸入一個正整數:", "求一個正整數的所有因子", int(rnd * 1000000 + 1))
print m & "的因子有:1 ";
if m > 1 then
for i = 2 to m
if m mod i = 0 then print i;
next i
end if
end sub
2樓:匿名使用者
private sub form_click()dim m as integer
dim stra as string
stra = 1
m = inputbox("輸入一個整數")if m = 1 then
msgbox m & "的所有因子:1," & mexit sub
end if
for i = 2 to m
if m mod i = 0 then
stra = stra & "," & im = m / i
end if
next i
msgbox m & "的所有因子:" & stra & ","
end sub
用vb編寫程式,輸入一個正整數n,求所有大於1且小於n,同時與n互質的數,存入一個陣列並每行5個的格式輸出
3樓:匿名使用者
同時與n互質的數 ------這個不太明白?能說一下嗎? 下面1000以內質數演算法。
private sub command1_click()text1.text = ""
for i = 1 to 1000
k = 1
for j = 2 to i / 2
if i mod j = 0 then k = 0next j
if k = 1 then
'print i
text1.text = text1.text & i & " "
end if
next i
end sub
4樓:
option explicit
dim s() as long
function hzs(byval n as long)redim s(n) as long
dim tmp1 as long, tmp2 as long, t*** as long
dim bl as boolean
for tmp1 = 2 to n
bl = true
for tmp2 = 2 to tmp1
if tmp1 mod tmp2 = 0 and n mod tmp2 = 0 then
bl = false
exit for
end if
next
if bl then
t*** = t*** + 1
s(t***) = tmp1
end if
next
'輸出for tmp1 = 1 to t***print s(tmp1),
if tmp1 mod 5 = 0 then printnext
end function
用vb編寫程式,求出介於正整數m,n之間所有包含4個因子的數(因子不包含1和自身)
5樓:匿名使用者
private sub command1_click()dim m as integer
dim n as integer
dim i as integer
m = inputbox("")
n = inputbox("")
for i = m to n
if getyz(i) = 4 then debug.print inext
end sub
private function getyz(inttmp as integer) as integer
getyz = 0
for i = 1 to inttmp
if inttmp mod i = 0 then getyz = getyz + 1
next
getyz = getyz - 2
end function
編寫程式,輸入正整數n,計算
int main double result int i int n scanf d n n for i 1 i n i if i 2 result result i 2 i 1 else result result i 2 i 1 printf result d n result return 0...
編寫程式,輸入正整數n,計算
public double sun int n return sum c語言編寫程式,輸入一個正整數n,計算1 1 3 1 5 的前n項之和。求過程 include int main for i 1 i n i printf sum 3f n sum return 0 示例執行結果 20sum 2....
編寫程式,輸入正整數,計算並顯示該整數的各位數字之和,例如123各位數之和是1 2 3,等於
include void main while m printf b d s 執行示例 var a,ans int64 begin readln a repeat ans ans a mod 10 a a div 10 until a 0 writeln ans end.關鍵while num 3....