VB-Tec.de Visual Basic - Technik, FAQ, Tricks, BeispieleHome / Allgemein / Entwicklung / PfuiHui Pfui oder Hui? - Schöner programmieren! |
Sub Pfui() For x = 2 To 999 a = True For s = 2 To x - 1 If x Mod s = 0 Then a = False Exit For End If Next s If a Then MsgBox x Next x End SubNachdem niemand auf die Lösung gekommen ist, präsentiere ich das nun folgende Programm und wiederhole die Frage:
Sub Hui()
Dim Kandidat As Long
Dim Teiler As Long
Dim IstPrim As Boolean
For Kandidat = 2 To 999
IstPrim = True
For Teiler = 2 To Kandidat - 1
If Kandidat Mod Teiler = 0 Then
IstPrim = False
Exit For
End If
Next Teiler
If IstPrim Then MsgBox Kandidat
Next Kandidat
End Sub
Jetzt sollte die Lösung schnell gefunden sein: Die beiden (semantisch äquivalenten) Programme bestimmen jeweils alle Primzahlen von 2 bis 999!© Jost Schwider, 30.04.2000-30.04.2000 - http://vb-tec.de/pfuihui.htm