Kamis, 17 November 2011

TP MODUL 6

2.A
program penjumlahan;
uses wincrt;

var
i,N,jumlah :integer;

begin
jumlah:=0;
writeln('Program Penjumlahan');
write('Masukkan Banyaknya Data Angka : '); readln(N);
write('Jumlahnya adalah : ');
for i:=1 to N do
begin
jumlah:=jumlah+i;
end;
writeln(' = ',jumlah);
writeln('YUDHA AGUNG WIRAWAN');
write('NIM:118110038');

end.

2.B
uses wincrt;
var
n:integer;
hasil:longint;
procedure jumlah(n:integer; var hasil:longint);
begin
if n=0 then
hasil:=hasil+0
else
begin
hasil:=hasil+n;
n:= n-1;
jumlah (n,hasil);
end;
end;
begin
clrscr;
writeLN('PROGRAM PENJUMLAHAN');
write('Masukkan Angka: ');readln(n);
jumlah(n,hasil);
writeln('HASILNYA ADALAH: ',hasil);
writeln('YUDHA AGUNG WIRAWAN');
writeln('NIM:118110038');
readln;
end.
3.
uses wincrt;
var x,y : integer;

procedure fpb(var x,y : integer);
var c :integer;
begin
if( x mod y = 0) and (y<=x) then write(y)
else
if (x<y) then fpb(y,x)
else
begin
c:=x mod y;
fpb(y, c);
end;
end;

begin
write('masukkan x : ');
readln(x);
write('masukkan y : ');
readln(y);
fpb(x,y);
writeln;
writeln('NAMA');
writeln('NIM:');
readln;
end.

4.
program segitiga_pascalalala;
uses wincrt;
var
x,y:integer;
function caridong(x,y:integer):integer;
begin
if (x=0) or (x=y)
then caridong:=x
else if x+1=y
then caridong:=1
else caridong:=caridong(x-1,y)+caridong(x-1,y-1);
end;
begin
writeln('Masukkan Angka:');
readln(x,y);
writeln('Hasil :',caridong(x,y));
writeln('YUDHA AGUNG WIRAWAN');
writeln('NIM:118110038');
readln;
end.

5.
program tribollaci;
uses wincrt;
var
i,n : integer;

function fib(n : integer) : integer;
begin
if (n = 1) then
fib := 1
else if (n = 2) then
fib := 1
else if (n = 3) then
fib :=1
else
fib := fib(n-1) + fib(n-2) + fib(n-3);
end;

begin
write('masukkan n : ');
readln(n);

for i := 1 to n do
write(fib(i), ' ');
writeln;
writeln('NAMA');
writeln('NIM : ');
end.

0 komentar:

Posting Komentar

Related Posts Plugin for WordPress, Blogger...

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | JCPenney Coupons