Date: Phone



Download 20,02 Kb.
Sana12.07.2022
Hajmi20,02 Kb.
#782704
Bog'liq
Test Lisp (2)


Name: ______________________________________________________
Date: ___________________ Phone:____________________________
Lisp is the second-oldest high-level programming language after Fortran. It was invented by John McCarthy in 1958. You might have noted that Lisp uses prefix notation.
a * ( b + c ) / d
will be written as:
(/ (* a (+ b c)) d)
Expression syntax sample below:
(function_name arg1 arg2 … argn)
Built-in functions in our examples (You can use only these functions and functions created by yourself)

(+ a b), (- a b)

arithmetic operations

(> a b), (< a b), (= a b)

comparison operations

(and a b), (or a b), (not a)

logical operations

(if predicate thenBody elseBody)

conditional operation

(define spec body)

defining custom functions


Define function description
(define (fname arg1 arg2 arg3 … argn)
(body)
)
Example
(define (sign n)
(if (> n 0) 1 -1)
)

  • (sign 2)

1

  • (sign -5)

-1

Exercises
All examples for positive integers
Example-1
(define (* a b)
(if (= b 1) a
(+ (* a (- b 1)) a)
)
)

  • (* 3 4)

12
Task-1. Write a function of division (/).
(define (/ a b)

)
Task-2. Write a function a % b. a and b are integers(a >= 0, b > 0).
Note: % - remainder of division. You cannot use multiplication(*) and division(/) operators!
Example-2. 4 % 3 = 1, 13 % 2 = 1.
Task-3. Write a function sum of all digits of number(n > 0).
Example-3. n = 122, f(n) = 1 + 2 + 2 = 5.
Task-4. Write a function to check whether it’s prime number or not.
1 - if it’s prime number, 0 - if it’s not prime number(n > 0).
Example-4. n=5, f(5)=1. n=8, f(8)=0.
Note: prime number - divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11).
Task-5. Write a function to convert the given decimal number into equivalent binary number(n>0).
Example-5. n=5, f(5)=101.
Download 20,02 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish