Mlente Banget

Posts Tagged ‘pascal


Tugas Pascal tentang looping/perulangan menggunakan fungsi for

uses wincrt;

var
kata: string;
i,j,pjg : byte;

begin
write(‘Masukkan Kata:’);readln(kata);

pjg:= length(kata);

for i:=1 to pjg do
begin
for j:=1 to i do
write(kata[j]);
writeln;
end;

for i:=1 to pjg do
begin
for j:=1 to pjg-i+1 do
write(kata[j]);
writeln;
end;
end.

Silahkan bagi yang memerlukan bisa langsung copy paste 😀

Advertisements

Tugas pascal menghitung nilai faktorial :

uses wincrt;
function fak(x:word):real;
begin
if x=0 then fak:=1
else fak:=x*fak(x-1);
end;

var n:word;z:real;
begin
writeln(‘=========================================’);
writeln(‘Tugas Algoritma – Nama/NIM Mahasiswa’);
writeln(‘=========================================’);
writeln;
write(‘Hitung Nilai Faktorial dari : ‘);
readln(n);
z:=fak(n);
writeln(‘Nilai Faktorial Dari ‘,n,’ adalah’,z:4:0);
writeln;
writeln(‘=========================================’);
end.

Apabila digambarkan sebagai berikut :

fak(5) => x<>0 => fak=5*fak(4) => fak=5*24 => 120
fak(4) => x<>0 => fak=4*abc(3) => fak=4*6 => 24
fak(31) => x<>0 => fak=3*abc(2) => fak=3*2 => 6
fak(2) => x<>0 => fak=2*abc(1) => fak=2*1 => 2
fak(1) => x=0 => fak=1 => fak=1 => 1
Proses rekursi dihentikan karena b=0 dan abc(5,0)=1.
Bila disimpulkan : fak(5) = 5*(4*(3*(2*(1))))
= 120

Selamat Mencoba


About Me

Unknown unordinary creature
 






October 2017
M T W T F S S
« Sep    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Blog Stats

  • 132,537 hits

Your Information

Tracker