Sabtu, 23 Mei 2015

pascal fpb rekrusif

program FPB_WITH_REKURSI;
 uses crt;
  var c,a,b,z,x,y:integer;

procedure fpb;
 begin
  if c < 1 then
   begin
    x:=0;
    y:=0;
    for z:=a downto 1 do
     begin
      if ((a mod z=0) and (b mod z=0)) then
       begin
        x:=x+1;
        if x=1 then
         begin
          writeln('FPB-nya adalah ',z);
          c := c+1;
          fpb;
         end;
       end;
     end;
    end;
  end;


begin
 clrscr;
  Writeln('---- PROGRAM CARI FPB ----');
  writeln('==========================');
  writeln;
  write('Inputkan bilangan pertama '); readln(a);
  write('Inputkan b ilangan kedua '); readln(b);
  fpb;
 readln;
end.

Tidak ada komentar:

Posting Komentar