1樓:匿名使用者
private function isprime(byref n as integer) as boolean '此函式用於判斷一個數是否素數dim j as integer
isprime = true
for j = 2 to n - 1
if n mod j = 0 then isprime = false: exit for
next
end function
用法dim i as integer ,n as integer for i =100 to 300if isprime (i) then print i,n=n+1if n mod 10 =0 then print '10個一行。endif next
2樓:聽不清啊
private sub command1_click()for i = 100 to 300
if prime(i) then
list1.additem i
end if
next i
end sub
function prime(n) as booleanprime = false
for i = 2 to sqr(n)
if n mod i = 0 then exit functionnext i
prime = true
end function
3樓:匿名使用者
我不懂vb 但粗略看得懂。。。 樓上的方法不好 100~300這個範圍可以用篩選法高效率求素數了 沒必要 2 to n-1
vb編寫程式求100到300之間的所有素數
4樓:
rivate function isprime(byref n as integer) as boolean '。此函式用於判斷一個數是否素數:
dim j as integer ;
isprime = true ;
for j = 2 to n - 1 ;
if n mod j = 0 then isprime = false: exit for ;
next ;
end function用法dim i as integer ,n as integerfor i =100 to 300if isprime (i) thenprint;
i,n=n+1if n mod 10 =0 then print '10個一行;
endifnext。
5樓:匿名使用者
很簡單的程式。。。
新建一個工程
from1上新增一個list1,用來顯示素數新增一個command1,用來操作
**如下:
private sub command1_click()dim i as long
for i = 200 to 300
if su(i) = true then '分析200-300區間所有的數是否為素數
list1.additem i '如果是素數就新增到list1中
end if
next
end sub
private sub form_load()command1.caption = "求素數"
end sub
private function su(snum as long) as boolean '求素數
su = true
for i = 2 to snum - 1if snum mod i = 0 thensu = false
exit function
end if
next
end function
6樓:士芮安
dim i as long, j as long, k as long
for i = 100 to 300
k = int(sqr(i))
for j = 2 to k
if i mod i = 0 then exit fornext j
if j > k then print jnext i
7樓:宛丘山人
for i=100 to 300
flag=0
for j=2 to 18
if mod(i,j)=0 then flag=1next j
if flag=0 then print inext i
編寫程式輸出下列圖形A ABA ABCBA ABCDCBA ABCDEDCBA希望有詳細的解釋謝謝(用vf
a abcde for i 1 to 5 b for j i 1 to 1 step 1 反著bai取字母 dub b substr a,j,1 endfor substr a,1,i b endfor 這個自己研究zhi 吧,dao也不好說 版清 權 clear for i 1 to 5 spac...
java編寫程式列印輸出以下圖形
public class diamond system.out.println for int i 4 i 1 i system.out.println 利用java 編寫程式,輸出以下圖案 string s 版int k 5 權for int q 0 q k q for int j 0 j 2 q...
C語言編寫程式,要求輸入整數,輸出其階乘
long func int num return tmp 程式如來 下 include stdio.h int main void printf 該數的zhi階乘為acc d n acc return 0 運用for迴圈來求階乘。執行結dao果 如求十的階乘 include main console...