Friday, 26 October 2012

Program Fibonacci (PASCAL)

program fibonacci;

uses crt;

var

   n:integer;

   i:integer;

   deret:array[1..100] of longint;

 

begin

    {deret fibonacci adalah deret yang merupakan hasil penjumlahan 2 bilangan sebelumnya}

    {7 awal deret fibonacci = 1,1,2,3,5,8,13,...}

     clrscr;

     write('Masukan jumlah deret :');

     readln(n);

     writeln;

     for i := 0 to n-1 do

     begin

          if (i = 0) or (i = 1) then

             begin

                  deret[i]:=1;

                  write(deret[i],' ');

             end

          else

              begin

                   deret[i]:=deret[i-1]+deret[i-2];

                   write(deret[i], ' ');

              end;

     end;

     readln;

end.

No comments:

Post a Comment