Autor Beitrag
heyhow
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Do 22.06.06 17:15 
Hallo,

habe folgendes Problem

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
for i := 1 to zahl-1 do
  begin
    if (zahl mod  i) = 0
    then
      label3.Caption := 'Zahl ist keine Primzahl!';
    end
  end;


Das ist ein Teil meines Sources. Ich möchte prüfen, ob die eingegeben zahl (in dem Falle die Variable zahl) eine Primzahl ist. Allerdings gibt er mit auch aus, dass die zahl eine Primzahl ist, wenn ich z.B. die 7 eingebe.. Das dürfte eigentlich nicht sein.

Wo liegt bei diesem Source der Fehler?
heyhow Threadstarter
Hält's aus hier
Beiträge: 7



BeitragVerfasst: Do 22.06.06 17:17 
Titel: Sorry
Oh, sorry!

Hab den Fehler schon gefunden :-)

Jede Ganzzahl ist durch 1 Teilbar....
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Do 22.06.06 17:45 
Die sieben ist auch tatsächlich eine Primzahl 8) :!:
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Do 22.06.06 18:18 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
for i := 2 to zahl-1 do
    if (zahl mod  i) = 0
    then
    begin
      label3.Caption := 'Zahl ist keine Primzahl!'
      exit;
    end;