Autor Beitrag
Glorfindelll
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mi 03.06.09 11:00 
Hallo.
Wie kann ich testen ob eine Zahl eine Primzahl ist?
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mi 03.06.09 11:04 
Wenn Sie nur durch 1 und sich selbst teilbar ist.
Wo liegt genau das Problem? Hast Du schon Ansätze?

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 03.06.09 11:07 
Hallo und :welcome: in der Entwickler-Ecke,

Ich könnte mir vorstellen, dass hier die Forensuche das eine oder andere Thema findet, was in eine Optimierungsschlacht ausgeartet ist. ;-)

Ob eine Zahl ganzzahlig durch eine andere teilen lässt, kann man mit Hilfe der MOD-Funktion bestimmen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
If Zahl MOD 2 = 0 then
  ShowMessage('Zahl ist durch 2 teilbar')
else
  ShowMessage('Zahl ist nicht durch 2 teilbar')

Das kann man dann leicht zu einem primitivem Primzahltester ausbauen.

_________________
We are, we were and will not be.
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Mi 03.06.09 11:59 
Hi und Willkommen.
Mit gausis vorschlag hast du im Prinzip alles was du brauchst.
Tip: Nur die Zahl 2 bedarf in diesem Beispiel einer sonderregelung.
Ansonsten sollte dir damit geholfen sein.

Viel Glück

mfg nic
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 03.06.09 14:23 
Weitere einschlägige Literatur gibt's www.delphi-forum.de/...pic.php?t=51842]hier und hier.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.