USMI IPB” ILKOM’S GROUP”

Just another WordPress.com weblog

pratikum sheme

*buatlah program sublist dari elemen ke m sbnyak n

contoh

>(sublist 2 3 ‘ (a b c d e f))

(b c d)

>(sublist 30 ‘ (a b c d e)

NULL

(define(sublist a n 1s)
(if (= n 0)
empty
(if (<= a 1)
(cons (car 1s) (sublist a(- n 1) (cdr 1s)))
(sublist (- a 1) n (cdr 1s))
)
)
)

*buat program yang mencetak suatu elemen x sebanyak 4 kali

>(cetakkali 4’b)

(bbbb)

jwb:

(define (cetakkali a x)

(if (<= a 0)

empty

(cons x(cetak kali (- a 1))

)

)

*buat program u/ menghitung rataan dan dari suatu list angka

cth:

>(rataan (1 2 3))

2

jwb: (define (jumlah x)

(if (= (length x)0) 0

(+ (car x) (jumlah ) (cdr x)))

)

)

(define ( rataan x)

(if ( = ( length x) 0) 0

(/ (jumlah x) (length x))

)

)

(define (jumlah x)

(if (null? x)

0

(+(jumlah (cdr x)) 1)

)

)

(define (sum x)

(if (null ? x)

0

(+ (car x) (sum (cdr x)))

)

)

(define (rataan x)

(/ (sum x) (jumlah x))

)

 



Maret 14, 2011 - Posted by | Uncategorized

Belum ada komentar.

Tinggalkan Balasan

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

Logo WordPress.com

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

Gambar Twitter

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

Foto Facebook

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

Foto Google+

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

Connecting to %s

%d blogger menyukai ini: