Acasa Tehnologie Divide et impera – Maxim dintr-un vector

Divide et impera – Maxim dintr-un vector

by Dragos Schiopu

programare

>

{maxim dintr-un vector cu divide et impera}
program maxim;
var v:array[1..10] of integer;
n,i:integer;

function max(i,j:integer):integer;
var a,b:integer;
begin
if i=j then max:=v[i]
else 
begin
a:=max(i,(i+j) div 2);
b:=max((i+j) div 2+1,j);
if  a>b then max:=a else max:=b;
end;
end;

begin
write('n= ');
readln(n);
for i:=1 to n do
begin
write('v[',i,']=');
readln(v[i]);
end;

writeln('max= ', max(1,n));
readln;
end.
{PascalZone.uv.ro}

s-ar putea sa-ti placa