vb求從10001100之間的所有素數輸出的結果

2021-12-19 02:54:34 字數 2231 閱讀 9863

1樓:翰林院裡掃地的

private sub command1_click()dim a%

a = 1000 '從1000開始找

doa = a + 1

if isprime(a) then '呼叫isprime()函式過程判斷a是否素數

text1.text = text1.text & " " & aend if

loop until a > 1100

end sub

'下面這個函式是用來判別一個數是否是素數的private function isprime(a as integer) as boolean

dim flag as boolean, b%flag = true

b = 2

do while b <= int(a / 2) and flagif int(a / b) = a / b thenflag = false

else

b = b + 1

end if

loop

isprime = flag

end function

2樓:匿名使用者

for a=1000 to 1100

if a mod 2<>0 then

text1.text=text1.text+cstr(a)+chr(13)+chr(10)

'//chr(13)+chr(10)是換行end if

next

vb題,輸出1000—1100之間的所有質數,每行輸出六個

3樓:匿名使用者

dim x, i, a(), n, r as integer, j as boolean

option explicit

private sub command1_click()n = -1

x = 1000

do while x <= 1100

j = true

i = 2

do while i < x

if int(x / i) = x / i then j = false

i = i + 1

loop

if j then

n = n + 1

redim preserve a(0 to n)a(n) = x

end if

x = x + 1

loop

for r = 0 to n

if int(r / 6) = r / 6 and r <> 0 then print vbcrlf;

print a(r);

next r

end sub

4樓:匿名使用者

'輸出 1000—1100 之間的所有質數,每行輸出六個private sub command2_click()dim x%, z%

dim m%, n%

x = 1000

z = 0

do while x <= 1100

x = x + 1

m = x - 1

n = 0

do while m > 2

if x mod m = 0 then n = n + 1m = m - 1

loop

if n = 0 then

print x;

z = z + 1

if z mod 6 = 0 then printend if

loop

end sub結果:

求1000到1100之間的所有質數,每行輸出6個,分多行輸出,用vb怎麼運算啊

5樓:白菜燉脂渣

dim i as integer ,n as integerfor i=1000 to 1100

if f(i)=true then

print i

n=n+1

if n=6 then

print

n=0end if

end if

next i

private function f(t as integer)as boolean

for i=2 to t-1

if t mod i=0 then

f=true

else f=false

end if

end function

vb求10 99之間隨機生成的是不是素數,若不是則繼續迴圈

dim i j k randomize doi int rnd 90 10 for j 2 to i 2 if i mod j 0 then exit fornext j loop while j i 2 text2.text i private sub form click dim i j k r...

vb程式設計題隨機產生不重複的A Z之間的英文字母,按字母順序輸出,每行

給你個思路。首先,定義20個陣列。然後在過程里弄個for迴圈,比如for i 1 to 20利用隨機函式,生成65 90之間的函式,賦值到變數,比如 str int 90 65 1 rnd 65 再弄個for迴圈,比如for j 1 to i判斷是否重複 if 陣列名 j str thencall ...

求用vb語言編寫好的軟體,如何用VB編寫一個簡單的減法程式?

module1 type student name as string age as integer birth as data adress as string end type form1 text1 text2.passwordchar command1 click if text1.text...