Вы находитесь на странице: 1из 2

program FPB_dan_KPK;

uses crt;
var x1,x2:integer;
procedure penentuan_faktor(var a:integer; var b:integer);
var i,j,fpb,kpk:integer;
status1,status2:boolean;
label 1,2,3,4;
begin
if (a mod b = 0) or (b mod a=0)
then
begin
if a=b then
begin
fpb:=a;
kpk:=a;
goto 3;
end;
if a<b then
begin
fpb:=a;
kpk:=b;
goto 3;
end
else
begin
fpb:=b;
kpk:=a;
goto 3;
end;
end;
for i:= 2 to a-1 do
if (a mod i <> 0) then
begin
status1:=true;
goto 1;
end
else for j:= 2 to b-1 do
if (b mod j <> 0) then status2:=true
else goto 2;
1:
if (status1=true) or (status2=true) then
begin
writeln('FPB = tidak ada');
writeln('KPK = ',a*b);
goto 4;
end;
2:
if a<b then
begin
for i:= 2 to a-1 do
if (a mod i = 0) and (b mod i = 0) then
begin
fpb:=i;
kpk:=(a*b) div fpb;
goto 3;
end;
end
else
begin
for j:= 2 to b-1 do
if (a mod j = 0) and (b mod j = 0) then
begin
fpb:=j;
kpk:=(a*b) div fpb;
goto 3;
end;
end;
3:
writeln('FPB = ',fpb);
writeln('KPK = ',kpk);
4:
end;

begin
clrscr;
write('Bilangan pertama : ');
readln(x1);
write('Bilangan kedua : ');
readln(x2);
writeln;
penentuan_faktor(x1,x2);
end.

Вам также может понравиться