Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hi, also ich möchte ein Prog schreiben in welches ich ein Intervall eingeben kann und das mir das Prog dann ausgibt welche Primzahlen in diesem Intervall liegen!

Mein Problem ist aber dabei das ich es nicht hinbekomme das alle Zahlen ausgegeben werden, sondern nur die größte Primzahl. Kann mir da jemand helfen?

Hier ist der Code wie ich ihn bis jetzt habe:

Option Compare Database

Option Explicit

Public z As Boolean

Public x As Double

Public y As Double

Private Sub Befehl2_Click()

If eingabe >= 1 And eingabe2 > eingabe Then

For x = eingabe To eingabe2

z = True

For y = 2 To x - 1

If x Mod y = 0 Then

z = False

End If

Next y

If z = True Then

ausgabe = x

End If

Next x

Else

ausgabe = "Es gibt keine Primzahlen in diesem Intervall!"

End If

End Sub

hab zwar nicht deinen eigentlichen Fehler so direkt gefunden aber zumindest kannste dir die Hälfte der Berechnungen sparen wenn du die zweite Schleife nur bis x/2 laufen lässt.

ich hab so das gefühl wenns zu einfach is, sehe ich meist die fehler ned :(

naja so gehts:

Option Compare Database

Option Explicit

Public z As Boolean

Public x As Long

Public y As Long

Public lala As String

Private Sub Befehl2_Click()

If eingabe >= 1 And eingabe2 > eingabe Then

For x = eingabe To eingabe2

z = True

For y = 2 To x - 1

If x Mod y = 0 Then

z = False

End If

Next y

If z = True Then

lala = lala & " " & y

ausgabe = lala

End If

Next x

Else

ausgabe = "Es gibt keine Primzahlen in diesem Intervall!"

End If

End Sub

Private Sub Befehl5_Click()

DoCmd.OpenForm "projekt"

DoCmd.Close acForm, "primzahl"

End Sub

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.