• Keine Ergebnisse gefunden

Exercise 4.1 LetP be the following LOOP-program

N/A
N/A
Protected

Academic year: 2022

Aktie "Exercise 4.1 LetP be the following LOOP-program"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Universität Koblenz-Landau FB 4 Informatik

Prof. Dr. Viorica Sofronie-Stokkermans1 15.11.2017

M.Ed. Dennis Peuter2

Exercises for Advances in Theoretical Computer Science Exercise Sheet 4

Due at 20.11.2017, 10:00 s.t.

Remark: For writing pseudocode, use the language that is dened at the home page of the exercise. For register machine programs, you are allowed to use the instructions dened at the home page of the exercise.

Exercise 4.1

LetP be the following LOOP-program.

loop x1 do x3:=x3+ 1 end;

// (1) loop x3 do

x2:=x2+x3

end;

// (2) x3:= 0

a) Fill in the following table with the values of the registers x1, x2, x3 at points (1) and (2) in the program: (i) for input 3; (ii) for input 5.

Input 3 x1 x2 x3

(1) (2)

Input 5 x1 x2 x3

(1) (2)

b) Which is the output of P for input 3? Which is the output ofP for input 5?

c) Which functionf :N→Nis computed byP?

Exercise 4.2

Letfac:N→N be dened, for everyn∈N, byfac(n) :=n!. a) Write a pseudocode program that computesfac.

b) Write a LOOP program that computesfac.

Exercise 4.3

Let the function fib:N→N be dened, for everyn∈N, by

fib(n) :=





1 if n= 0

1 if n= 1

fib(n−1) +fib(n−2) otherwise.

a) Write a pseudocode program that computesfib.

b) Write a WHILE program that computes fib.

(2)

Exercise 4.4

a) Let DIV10:N→Nbe dened, for everyn∈N, byDIV10(n) is the result of the integer division of nby 10.

I) Write a pseudocode program that computes DIV10. II) Write a GOTO program that computes DIV10.

b) Let MOD10:N→N be dened, for every n∈N, by MOD10(n) is the remainder after the division of nby 10.

I) Write a pseudocode program that computes MOD10. II) Write a GOTO program that computes MOD10.

c) Let q:N→N be dened, for everyn∈N, byq(n) is the sum of the digits in n. I) Write a pseudocode program that computes q.

II) Write a GOTO program that computes q.

Remark: You are allowed to use DIV10 and MOD10 as auxiliary programs.

1 B 225 sofronie@uni-koblenz.de https://userpages.uni-koblenz.de/~sofronie/

2 B 223 dpeuter@uni-koblenz.de https://userpages.uni-koblenz.de/~dpeuter/

If you want to submit solutions, please do so until 20.11.2017, 10:00 s.t. via the cardboard box in the shelf in room B 222 or via e-mail (with Homework ACTCS in the subject) to dpeuter@uni-koblenz.de.

Referenzen

ÄHNLICHE DOKUMENTE

a certain graph, is shown, and he wants to understand what it means — this corre- sponds to reception, though it involves the understanding of a non-linguistic sign;

Aby Warburg was deeply convinced that the cultural historic significance of images lies precisely in these image atoms and their interrelations.. With the full seriousness

via the cardboard box in the shelf in room B 222 or via e-mail (with Homework ACTCS in the subject)

via the cardboard box in the shelf in room B 222 or via e-mail (with Homework ACTCS in the subject)

Remark: For the exercises where you have to dene primitive recursive functions, you are allowed to use all functions that were proved to be primitive recursice in the lecture or in

via the cardboard box in the shelf in room B 222 or via e-mail (with Homework ACTCS in the subject)

Remark: For the exercises where you have to define primitive recursive functions, you are allowed to use all functions that were proved to be primitive recursive in the lecture or in

Remark: For writing pseudocode, use the language that is defined at the home page of the exercise..