erif " :i teger#: i teger$ begi if %1 t&e if !' ()!erific " *1# t&e !erif:+!erif " *1# else !erif:+ !' ( else !erific:+ !'1( e d$ a# b# c# d# i t !erif "i t # , if " %-# if "!' *1()!erif " *2## retur !erif " *2#$ else retur !' *1($ else retur !'-($ .
/etermi 0 c1te eleme te di !ector su t mai mari dec1t 2erific0 dac0 toate eleme tele di !ector su mai mici sau egale cu Calculeaz0 maximul eleme telor !ectorului ! Calculeaz0 mi imul eleme telor !ectorului ! 3: c#
2. 4ie subprogramul de tip fu cie5 recursi!: fu ctio !erific " :i teger# : boolea $ begi if )+1 t&e !erific:+"!'1(%+-# else !erific:+"!' (%-#or !erific " *1# e d$ a# b# c# d# /etermi 0 c1te eleme te di 2erific0 dac0 !ectorul ! cu 2erific0 dac0 !ectorul ! cu /etermi 0 c1te eleme te di i t !erific " i t # ,if " )+1# if "!'1(%+-# retur 1 else retur else if "!' (%+-#66"!erific " *1#+ +1# retur 1 else retur -$ .
!ectorul ! su t strict poziti!e compo e te au umai eleme te strict poziti!e compo e te are cel pui u eleme t poziti! !ectorul ! su t egati!e 3: c#
7. 4ie subprogramele procedure i ! " :b8te#$ begi 9rite " #$ if %1 t&e i ! " *1# e d$ procedure direct " :b8te#$ begi if %1 t&e direct " *1#$ 9rite " #$ e d$
!oid i ! "c&ar # , pri tf ":;d<5 # if " %1# i ! " *1#$ . !oid direct "c&ar # ,if " %1# direct" *1#$ pri tf ":;d<5 #$ .
=recizai ce se !a tip0ri dac0 +> ? a# > 7 2 1 2 7 > b# > 7 2 2 7 > c# > 7 2 1 1 2 7 > d# > 7 2 1 - - 1 2 7 > 3 : c# >. 4ie subprogramul de mai jos : fu ctio test "@ :i teger# : i teger$ begi if @)7 t&e test:+1 else test:+ test "@*1#Atest "@*2#A1$ e d$ Ce !aloare are test "test ">## ? a# b# c# d# 1 B > C 3: d# D. Completai fu cia de mai jos cu i struciu ile ecesare pe tru a calcula um0rul apariiilor u ui eleme t E F tr*u !ector ! cu compo e te: fu ctio ap "x5@ :i teger#: i teger$ begi if @+- t&e ap:+ f# else if !'@(+x t&e ap:+ d# else ap:+a# e d$ a# b# c# d# e# f# ap "x5 @*1# ap "x5@*2#A ap "x5@*1# ap "x5@# 1A ap "x5@*1# 1 i t ap "i t x5 i t @# , if "@ + +-# retur f# else , if "!'@(+ +x# retur d# else retur a# . . i t test "i t @# , if "@)7# retur 1$ else retur test "@*1#A test "@*2#A1$ .
G.
4ie fu cia recursi!0: i t test "i t # , if " %+12# retur *1 else retur test "test" A2## .
fu ctio test " :i teger#:i teger$ begi if %+12 t&e test:+ *1 else test:+test"test" A2## e d$ Ce !aloare au test"H# ? a# 17 b# H c# 11 d# iciu a di a5b5c u e !ariata corecta
3: c# H. 4ie fu cia recursi!0: i t ael " i t 5 i t @# , if "@% I2# retur else if " ;@+ +-# retur 1 else retur ael " 5 @A1#$ .
fu ctio ael " 5@ : i teger#:i teger$ begi if @%" di! 2# t&e ael:+ else if mod @+- t&e ael:+1 else ael:+ael" 5@A1#$ e d$ Ce !aloare are fu cia ael "1-57# ? a# 1 b# c# programul cicleaz0 d# exist0 erori de compilare
3: a# C. Se co sider0 fu cia recursi!0: i t ael2 "i t # , if "K" ;2## retur I2$ else retur ael2 "ael2 "7J A1## . fu ctio ael2 " :i teger#: i teger$ begi if mod 2+- t&e ael2+ di! 2 else ael2:+ ael2 "ael2 "7J A1## e d$ 1. Care este !aloarea fu ciei ael2 "G# ? a# 1 b# 11 c# 17
d# programul se bloc&eaz0 3: c# 2. /e c1te ori este apelat0 fu cia ael2 "G# ? a# 1G b# G c# 17 d# u i tr0 F execuie 3: b#