Autor Beitrag
ololo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Sa 23.06.07 14:15 
hi delphiforum

ich habe ein problem
ich versuche eine zeile vom pascalschen dreieck auszugeben, doch es kommt an der markierten stelle der fehler:
"Der linken Seite kann nichts zugewiesen werden"

hier ist der quelltext zu dem problem:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
procedure TForm1.Button1Click(Sender: TObject);

function Fakultaet(const n : integer) : int64;
var k : integer;

begin
   Result := 1;

   for k := 1 to n do
   Result := K*Result;
end;

function formel(const k, n : integer) : integer;
var s : string;
    x : integer;

begin
   Result := Fakultaet(n) div (Fakultaet(k) * fakultaet(n-k));

   Memo1.Clear;
   Memo1.Alignment := taCenter; //text zentriert

   s := '';

   for k := 0 to n do                     //hier ist der fehler!!!
   begin
      s := s+inttostr(formel(k, n))+'';
   end;

   Memo1.Lines.Add(s);
end;
end;


ich hoffe ihr könnt mir helfen

gruß


Moderiert von user profile iconGausi: Topic aus VCL (Visual Component Library) verschoben am Sa 23.06.2007 um 17:54
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 23.06.07 14:17 
1. k ist als 'const' (konstanter) Parameter deklariert. Einer Konstante kann man nix zuweisen
2. k ist ein Parameter und kann als For-Laufvariable nicht verwendet werden.

Du musst eine lokale Variable verwenden.

_________________
Na denn, dann. Bis dann, denn.
ololo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Sa 23.06.07 16:06 
danke

ok den fehler konnte ich jetzt beheben, aber wenn ich es jetzt etwas größere zahlen benutze ( >30 ) dann kommt irgend wie ein fehler, es entstehen negative zahlen...die auch nicht nur die zahl im negativen sind, sondern komplett falsche...

gruß
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 23.06.07 16:53 
Das liegt dann daran, dass du Fakultäten zum Berechnen nimmst. Bei 30! kommts dann wohl zu nem Integer-Überlauf. Wenn du das Dreieck direkt berechnest, kommst du weiter.

_________________
We are, we were and will not be.
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: So 24.06.07 23:13 
Wenn sogar z.B. nur die Teilbarkeit durch eine bestimmte Zahl von Interesse ist, kann man durch Nutzung des Mod-Operators sogar ohne Begrenzung weit berechnen (allerdings nur bei zeilenweise Berechnung) ...

Für die Zeilenweise Berechnung kann man z.B. sowas hier nehmen:
OMathGeneral.pas Funktion BinomialRow.

_________________
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.