当前位置:编程学习 > VB >>

vb闅忔満鏁伴棶棰?- 宸茶В鍐?- 鎼滄悳闂棶

鍒╃敤闅忔満鍑芥暟浜х敓80涓?0锝?9涔嬮棿鐨勯殢鏈烘暣鏁帮紝灏嗗叾涓殑鍋舵暟鎸夌敱灏忓埌澶х殑椤哄簭鎺掑垪骞惰緭鍑猴紝灏嗗鏁版寜鐢卞ぇ鍒板皬鐨勯『搴忔帓鍒楀苟杈撳嚭锛涘湪浜х敓鐨?0涓殢鏈烘暣鏁颁腑锛屾壘鍑哄叾涓殑绱犳暟锛岃姹傦細

灏嗛殢鏈轰骇鐢熺殑80涓暣鏁板瓨鍏ユ暟缁勶紝鎸夋瘡琛?0涓暟杈撳嚭鍒扮獥浣撴垨鏂囨湰妗嗕腑銆?/p>

2锛庡伓鏁板拰濂囨暟涔熷垎鍒瓨鍏ユ暟缁勶紝灏嗘帓濂藉簭鐨勫伓鏁板拰濂囨暟鍒嗗埆杈撳嚭鍒扮獥浣撴垨涓や釜鏂囨湰妗嗕腑銆?/p>

3锛庣敤Sub瀛愯繃绋嬫垨Function鍑芥暟杩囩▼鍒ゆ柇闅忔満鏁存暟鏄惁涓虹礌鏁般€?/p>

4锛庡皢绱犳暟鎸夋瘡琛?0涓暟鍦ㄧ獥浣撴垨鏂囨湰妗嗕腑杈撳嚭銆?/p>5锛庡皢绱犳暟鐨勪釜鏁板強姹傚拰缁撴灉杈撳嚭鍒扮獥浣撴垨鏂囨湰妗嗕腑

答案:Dim a(80), b, c, d, f, h
Public Function ss()
Print
c = 0
Print "绱犳暟鏄?"
 For b = 1 To 80
  If a(b) Mod 2 <> 0 And a(b) Mod 3 <> 0 And a(b) Mod 5 <> 0 And a(b) Mod 7 <> 0 Then
   Print a(b);
   d = d + a(b)
   c = c + 1
   If c Mod 10 = 0 Then
    Print
   End If
  End If
 Next
Print
Print
Print "绱犳暟涓暟鏄?" & c
Print "绱犳暟鐨勫拰鏄?" & d
End Function

Private Sub Command1_Click()
Cls
Print "浜х敓80涓?0锝?9涔嬮棿鐨勯殢鏈烘暣鏁版槸:"
Randomize
For b = 1 To 80  '闅忔満鍑芥暟浜х敓80涓?0锝?9涔嬮棿鐨勯殢鏈烘暣鏁?br>a(b) = Int((Rnd * 90) + 10)
Print a(b);
If b Mod 10 = 0 Then
Print
End If
Next
'鍋舵暟鐢卞皬鍒板ぇ
For b = 1 To 80
  For c = b To 80
   If a(c) > a(b - 1) Then
    d = a(b - 1)
    a(b - 1) = a(c)
    a(c) = d
    End If
  Next
Next
Print "鍋舵暟鐢卞皬鍒板ぇ"
For b = 1 To 80
If a(b) Mod 2 = 0 Then
  Print a(b);
  f = f + 1
  If f Mod 10 = 0 Then
  Print
 End If
End If
Next
'濂囨暟澶у埌灏?br>For b = 1 To 80
  For c = b To 80
   If a(c) < a(b - 1) Then
    d = a(b - 1)
    a(b - 1) = a(c)
    a(c) = d
    End If
  Next
Next
Print
Print "濂囨暟澶у埌灏?
For b = 1 To 80
If a(b) Mod 2 <> 0 Then
 Print a(b);
 h = h + 1
 If h Mod 10 = 0 Then
  Print
 End If
End If
Next
ss  '璋冪敤Function鍑芥暟杩囩▼
End Sub

Private Sub Command1_Click()

Dim i, j, s, nb, nc, nd, nn, a(80), b(80), c(80), d(8) As Integer

For i = 1 To 80

    a(i) = 99 - Int(Rnd * (99 - 10))

Next

Print "闅忔満浜х敓鐨?0涓?0锝?9涔嬮棿鐨勬暣鏁帮細"

For i = 1 To 80 Step 10

    For j = 0 To 9

        If i + j > 80 Then Exit For

        Print a(i + j),

    Next

    Print

Next

 

nb = 0

nd = 0

For i = 1 To 80

    If a(i) Mod 2 <> 0 Then

       nb = nb + 1

       b(nb) = a(i)  ' 濂囨暟

    Else

       nd = nd + 1

       d(nd) = a(i)  ' 鍋舵暟

    End If

Next

 

For i = 1 To nd

    For j = i + 1 To nd

        If d(i) > d(j) Then

           s = d(i)

           d(i) = d(j)

           d(j) = s

        End If

    Next

Next

Print "浠庡皬鍒板ぇ鎺掑簭鐨勫伓鏁帮細"

For i = 1 To nd Step 10

    For j = 0 To 9

        If i + j > nd Then Exit For

        Print d(i + j),

    Next

    Print

Next

 

For i = 1 To nb

    For j = i + 1 To nb

        If b(i) < b(j) Then

           s = b(i)

           b(i) = b(j)

           b(j) = s

        End If

    Next

Next

Print "浠庡ぇ鍒板皬鎺掑簭鐨勫鏁帮細"

For i = 1 To nb Step 10

    For j = 0 To 9

        If i + j > nb Then Exit For

        Print b(i + j),

    Next

    Print

Next

 

nc = 0

nn = 0

For i = 1 To 80

    If f(a(i)) = True Then

       nc = nc + 1

       c(nc) = a(i)  鈥?绱犳暟

       nn = nn +c(nc)

    End If

Next

Print "绱犳暟鍏憋細" & Format(nc) & " 涓紝绱犳暟涔嬪拰涓猴細" & Format(nn)

For i = 1 To nc Step 10

    For j = 0 To 9

        If i + j > nc Then Exit For

        Print c(i + j),

    Next

    Print

Next

End Sub

 

Function f(ByVal n As Integer) As Boolean  鈥?鍒ゆ柇鏄惁涓虹礌鏁扮殑鍑芥暟

' 鑻ヤ负绱犳暟锛屽垯杩斿洖True锛涘惁鍒欙紝杩斿洖False

Dim i As Integer

Dim s As Boolean

 

If n <= 1 Then

   f = False

   Exit Function

End If

If n = 2 Then

   f = True

   Exit Function

End If

For i = 2 To n - 1

    If n Mod i = 0 Then

       f = False

       Exit Function

    End If

Next

f = True

End Function

璇炬湰涓婂氨鑳芥壘鍒扮殑涓滆タ锛岃繕鏄嚜宸辨壘鎵惧惂銆傘€傘€?/p>

Rnd()    '闅忔満鏁板嚱鏁?/p>

鐢熸垚鏌愪釜鑼冨洿鍐呯殑闅忔満鏁存暟锛屽彲浣跨敤浠ヤ笅鍏紡锛?nbsp;  
  Int((upperbound   -   lowerbound   +   1)   *   Rnd   +   lowerbound)   
  杩欓噷锛寀pperbound   鏄殢鏈烘暟鑼冨洿鐨勪笂闄愶紝鑰?  lowerbound   鍒欐槸闅忔満鏁拌寖鍥寸殑涓嬮檺銆?/p>

"鐢卞皬鍒板ぇ鐨勯『搴忔帓鍒?鐢卞ぇ鍒板皬鐨勯『搴忔帓鍒? 瑕佺敤鍒版暟缁勫啋娉℃帓搴忎簡

鐢熸垚闅忔満鏁扮殑澶氬皯,鍒ゆ柇鏄惁"鍋舵暟","濂囨暟","绱犳暟"鍙婂瓨鍏ョ浉搴旀暟缁勮繖涓啓娈靛垽鏂▼搴忓惂

上一个:谁是VB高手?
下一个:VB控件的制作

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,