RSS

Faktor Prima dan Faktorisasi Prima

04 Okt

Program FBPrima;
uses crt;

Const

prima : array [1..25] of integer = (2,3,5,7,11,13,17,23,27,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97);

type
larik = array [1..100] of integer;

var
Bil,i,sb,jfb,p,fbp : integer;

KBil : String[25];
fb : larik;

begin
 clrscr;

REPEAT
  BEGIN  
    CLRSCR;
    WRITE (‘Masukan Bilangan (1..1000) : ‘);READLN(Bil);
  END;
 UNTIL (Bil >= 1 );

 jfb := 0;
 p := 1;
 fbp := Bil;
 REPEAT
 BEGIN
    sb := fbp Mod prima[p];
    if sb = 0 then  
    begin
         jfb := jfb + 1;
         fb[jfb] := prima[p];
         fbp := fbp div prima[p];
    end
    else
    begin
         p := p + 1;
         if fbp < prima[p] then
         begin
            {
            jfb := jfb + 1;
        fb[jfb] := fbp;    }
        p := 0;
         end;
    end;      
 END;
 UNTIL (P = 0) ;

 write(‘Faktor Bilangan Prima ‘,Bil,’ adalah ‘);
 for i:= 1 to jfb do
 begin
    write (fb[i],’, ‘);
 end;
 writeln(”);

 fbp := Bil;
 for i:= 1 to jfb do
 begin

    writeln(fbp,’ : ‘,fb[i],’ = ‘,fbp Div fb[i]);
    fbp := fbp div fb[i];
 end;
 writeln(”);

 fbp := 1;
 write(‘Faktorisasi Prima Bilangan ‘,Bil ,’ = ‘);
 for i:= 1 to jfb do
 begin
    write(fb[i]);
    fbp := fbp * fb[i];
    if i = jfb then write(‘ = ‘) else write(‘ x ‘);
 end;
 write(fbp);
 writeln(”);
end.

 

Jika program diatas dijalankan :

Masukan Bilangan (1..1000) : 243
Faktor Bilangan Prima 243 adalah 3, 3, 3, 3, 3,
243 : 3 = 81
81 : 3 = 27
27 : 3 = 9
9 : 3 = 3
3 : 3 = 1

Faktorisasi Prima Bilangan 243 = 3 x 3 x 3 x 3 x 3 = 243

About these ads
 
Tinggalkan komentar

Ditulis oleh pada Oktober 4, 2011 in Free Pascal

 

Berikan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Logout / Ubah )

Twitter picture

You are commenting using your Twitter account. Logout / Ubah )

Facebook photo

You are commenting using your Facebook account. Logout / Ubah )

Google+ photo

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

 
Ikuti

Get every new post delivered to your Inbox.

%d blogger menyukai ini: