Anda di halaman 1dari 2

PSEDUDOCODE PROGRAM FPB

DEKLARASI
fpb (int x, int y): int
ValidasiInput (int *var): int
hasil, x, y, gcd, i = int
PROCEDURE
main : int
BEGIN
WHILE(1)
Scan bilangan pertama
IF ValidasiInput(&x) then
break;
Print “Maaf, Inputan Anda Salah!”
END IF
END WHILE
WHILE(1)
Scan bilangan kedua
IF ValidasiInput(&x) then
break;
Print “Maaf, Inputan Anda Salah!”
END IF
END WHILE

//fpb rekursif
hasil=fpb(x,y)
print fpb rekursif

//fpb iteratif
FOR i=1; i <= x && i <= y; ++I then
IF x%i==0 && y%i==0 then
gcd = i
END IF
Print fpb iteratif
END FOR
RETURN
END
END PROCEDURE

DEKLARASI
hasil, sisabagi: int
PROCEDURE
fpb (int x, int y): int
BEGIN
IF y<=x && x%y==0 then
return(y)
ELSE IF x<y then
hasil=fpb(y,x)
return(hasil)
ELSE
sisabagi=x%y
hasil= fpb(y,sisabagi)
return(hasil)
END IF
END
END PROCEDURE
DEKLARASI
search[1024], x: char
PROCEDURE
ValidasiInput (int *var): int
BEGIN
IF fgets(search, sizeof(search), stdin) !=NULL then
IF sscanf(search, "%d %c" , var, &x) == 1 then
return 1
ENDIF
ELSE
return 1
END IF
return 0
END
END PROCEDURE