• date post

14-Jan-2017
• Category

## Education

• view

1.867

0

Embed Size (px)

### Transcript of ΠΛΗ10 ΜΑΘΗΜΑ 2.6

• 10 2:

2.6:

• A. 1. 2.

1. 2. 3. 4. 5. 6. 7.

3. 1.

. 1. 2.

, 10, 2.6:

2

. 1. 2. 3. 4. (swap)5.

1. : 2. : 3. : 4. : 5. : 6. : 7. : 8. :

6. 1. : 2. : 3. :

7. 1. : 2. : 3. : 4. :

• A. 1.

3 , 10, 2.6:

.

5 1 5 1

. .. 2, 2 (

) : 5 2 1 5 2 1 11 ( )

.. 15, 15 ( 15) 5 15 1 5 15 1 76 ( 76)

• A. 1.

4 , 10, 2.6:

:

. .. ,

.. search() .

. -, main ! .

• A. 2. 1.

5 , 10, 2.6:

: orismos_sinartisis

a,b: INTEGER;

cube(x): INTEGER

• A. 2. 2.

6 , 10, 2.6:

( ). :

:

cube: x .

. , . ,

.

_( ): __

cube(x) : INTEGER

• A. 2. 3.

7 , 10, 2.6:

: : : (

)

:

1: , . 2: .

_: _;

_: _;

x: INTEGER;

cube: INTEGER;

• A. 2. 4.

8 , 10, 2.6:

. -

( )

( ).

.

/* */

/* */-

cube:=x*x*x;-

• A. 2. 5.

9 , 10, 2.6:

, . : :

. . !

( 2 )

.

b:=cube(a);

• A. 2. 6.

10 , 10, 2.6:

: : square

. f x :

2x+1 :

a . b c f(c). .

• A. 2. 7.

11 , 10, 2.6:

: ( ) ( ! , ..

. .

: .

..

: .

, !

. . .

• A. 2. 7.

12 , 10, 2.6:

local_global

x,ret:INTEGER; /* Katholiki metavliti: Tin vlepoun oloi */

f1(): INTEGER

f1: INTEGER;

a,x:INTEGER; /* Topikes metavlites tis f1*/

a:=2;x:=0;/* Exoyme diplo onoma stin x.

Epikratei to topiko onoma */(EOLN,f1: a=,a,,x=,x);f1:=0;

-

f2(): INTEGER

f2: INTEGER;

a:INTEGER; /* Topikes metavlitestis f2*/

a:=8;x:=7; /*Anaferetai sti katholiki x */ (EOLN,f2: a=,a,,x=,x);f2:=0;

-

x:=5;(EOLN, : x=,x);ret:=f1();(EOLN, : x=,x);ret:=f2();(EOLN, : x=,x);

• A. 3. 1.

13 , 10, 2.6:

, .

!

a:=5, :

a b

a b

5

functions

a,b: INTEGER;

f(x):INTEGER

x:INTEGER

f:INTEGER

f:=x*x;-

a:=5;b:=f(a);

• A. 3. 1.

14 , 10, 2.6:

f a. ! ,

f. f, x

, x 5.

x a.

f, f=x*x f 25

functions

a,b: INTEGER;

f(x):INTEGER

x:INTEGER

f:INTEGER

f:=x*x;-

a:=5;b:=f(a);

a b

5

f

x f5

a b

5

f

x f5 25

• A. 3. 1.

15 , 10, 2.6:

, f 25 . ! (25) b. f,

:

functions

a,b: INTEGER;

f(x):INTEGER

x:INTEGER

f:INTEGER

f:=x*x;-

a:=5;b:=f(a);

a b

5 25

! !

, ( ): (

) ( )

• B. 1.

16 , 10, 2.6:

(+) :

, : .: , ..

.

.:

, .

. ..

. .

• B. 2.

17 , 10, 2.6:

: , - :

.

. ,

. -- (call-by-value).

, , % .

, .

-- (call-by-reference). % .

• . 2. 1.

18 , 10, 2.6:

call_by_value

x:INTEGER;

f(a)

a: INTEGER; /* */

/* */

/* */

a:=2; /* call by value */(EOLN,f: a=,a);

-

x:=0;(EOLN, : x=,x); /* 0 */ f(x); /* */(EOLN, : x=,x); /* 0. */

• . 2. 2.

19 , 10, 2.6:

call_by_reference

x:INTEGER;

f(%a)

a: INTEGER; /* a . */

a: INTEGER; /* . */

/* */

a:=2;(EOLN,f: a=,a); /* 2 */

-

x:=0;(EOLN, : x=,x); /* 0 */ f(%x); /* */(EOLN, : x=,x); /* 2. */

• , 10, 2.6: 20

.

, . .

, .

, .

• . 1:

, 10, 2.6:

: get_integer(start, finish) :

[startfinish] . .

a,b 1..10 n 2..5 n*(a-b) .

21

• . 2:

, 10, 2.6:

: is_even(n) : TRUE FALSE n is_odd(n) : TRUE FALSE n is_square(n) : TRUE FALSE n

is_cube(n) : TRUE FALSE n

main

. :

22

: 8

: 9

• . 3:

, 10, 2.6:

() . 1 .

: is_prime(n)

n, TRUE FALSE .

( >0) (.. a=5, b=8) .

:

23

: 5 : 15

5 7 11 13

• . 4: (swap)

, 10, 2.6:

swap

swap:

24

a: 5 b: 8

: a=8, b=5 : a=5, b=8

• . 5.1: :

, 10, 2.6:

.

25

• . 5.2: :

, 10, 2.6:

. , print_array.

.

26

• . 5.3: :

, 10, 2.6:

. , min_array.

.

27

• . 5.4: :

, 10, 2.6:

. , max_array.

.

28

• . 5.5: :

, 10, 2.6:

, mo_array.

.

29

• . 5.6: :

, 10, 2.6:

, mo_array.

.

30

• . 5.7: :

, 10, 2.6:

. , mo_array.

.

31

• . 5.8: :

, 10, 2.6:

: (510)

. , , ,

.

32

• . 6.1: :

, 10, 2.6:

. , linear_search.

, TRUE FALSE .

33

• . 6.2: :

, 10, 2.6:

. , binary_search.

, TRUE FALSE .

34

• . 6.3: :

, 10, 2.6:

: (510)

( get_integer ).

( ).

.

35

• . 7.1: :

, 10, 2.6:

Selection Sort . , selection_sort.

.

36

• . 7.2: :

, 10, 2.6:

Insertion Sort . , insertion_sort.

.

37

• . 7.3: :

, 10, 2.6:

Bubble Sort . , bubble_sort.

.

38

• . 7.4: :

, 10, 2.6:

: (510)

( get_integer ).

. .

39