1樓:遠風的夢想家
private sub form_click()n = inputbox("請輸入
乙個正整數(
內>=3)")
k = int(sqr(n))
i = 2
swit = 0
do while i <= k and swit = 0if n mod i = 0 then
swit = 1
else
i = i + 1
end if
loop
if swit = 0 then
print n; "是
容"else
print n; "不是"
end if
end sub
2樓:同翠柏位紫
dimflag
asbyte
:flag=0
fori=2
toint(n/2)ifn
modi=0
then
flag=1
exit
forend
ifnext
i執行完
bai後,flag為0的話,
du說明是素數zhi;為1的話,是合dao數。可根據相內應要求編寫後續**容
在vb中編寫乙個判斷乙個整數是否為素數的程式.....能不能簡單點....用if 5
3樓:匿名使用者
function sushu(a as integer) as boolean
dim i as integer
for i = 2 to int(sqr(a))if a mod i = 0 then exit fornext
if i > int(sqr(a)) thensushu = true
else
sushu = false
end if
end function
private sub form_click()dim a as integer
a = inputbox("輸入
du乙個整
數zhi
dao", "提示")
if sushu(a) = true thenmsgbox cstr(a) + " 是素數回"else
msgbox cstr(a) + " 不是答素數"
end if
end sub
c語言程式設計判斷輸入的正整數是否為素數
素數 有無限個,除了1和它本身以外不再有其他的因數。所以可以通過for迴圈從2到n 1依次整除n如果能整除則不是素數,否則就是素數。參考 include int fun int n 判斷n是否是素數int i for i 2 i include int main if g 0 printf yes ...
VB的程式設計,輸入任意的正整數要把它逆序輸出
最簡單的方法 msgbox strreverse inputbox 請輸入乙個正整數 符合你題意的方法 dim s1 as string,s2 as string,i as integer s1 inputbox 請輸入乙個正整數 for i len s1 to 1 step 1s2 s2 mid ...
C 語言輸入正整數,判斷它是否是迴文數
問明 include stdio h include stdlib h int main int num,k,n 0 printf 請輸入一個數 scanf d num k num while k 0 n n 10 k 10 k k 10 if n num printf d是迴文數 n else p...