eMatematikas Prisijunk Forumas Užduotys Testai Pradžia

Fibonačio skaičių seka 1 1 1 3 5 9 ir t.t


https://www.ematematikas.lt/upload/uploads/50000/6000/56165/thumb/p19ef2c837jtdsgbmb2ave1g0p1.png

Sveiki. Gal kas galetu pagelbet, kaip reiktu sukurti sia programa?


if(n<=3) return 1;
int f1=1, f2 = 1, f3 = 1, temp;
for(int i = 4; i <= n; i++){
  temp = f3;
  f3 = f1 + f2 + f3;
  f1 = f2;
  f2 = temp;
}
return f3;

Kodo netestavau ir net nekompiliavau.

ir Delphi


{* Programavimo paslaugos. Skype: EdijusKole *}
function SuperFibonacci(const AIndex: Integer): Integer;
var
  i: Integer;
  a, b, c, d: Integer;
begin
  if (AIndex <= 3) then
  begin
    if (AIndex < 1) then
      result := 0 // Error, raise exception
    else
      result := 1;
  end
  else
  begin
    a := 1;
    b := 1;
    c := 1;
    for i := 4 to AIndex do
    begin
      d := c;
      c := a + b + c;
      a := b;
      b := d;
    end;
    result := c;
  end;
end;

pakeista prieš 11 m

Nori sudalyvauti šioje temoje ir parašyti savo pranešimą? Prisijungti »