Sunteți pe pagina 1din 3

Proceduri si Functii

1. Fie dat tabloul unidimensional a[1..10] of real, de determinat


suma elementelor acestui tablou utilizind procedura.
Program P1;
type tab=array[1..10] of real;
var a:tab;
i,n:integer;
s:real;
procedure suma(var :tab; n:integer; var sum:real!;
var i:integer;
begin
sum:=0;
for i:=1 to n do
sum:=sum"[i];
end;
begin#main$
%rite(&n=&!; readln(n!;
%rite(&dati elementele tabloului:&!;
for i:=1 to n do readln(a[i]!;
suma(a,n,s!;
%rite(&s=&,s:':(!;
end.

2. Fie dat tabloul unidimensional a[1..10]of real, de determinat suma
elementelor acestui tablou utilizind o functie.
Program P(;
type tab=array[1..10] of real;
var a:tab;
i,n:integer;
s:real;
function suma(:tab; n:integer!:real;
var i:integer;
):real;
begin
):=0;
for i:=1 to n do
):=)"[i];
suma:=);
end;
begin#main$
%rite(&n=&!; readln(n!;
%rite(&dati elementele tabloului:&!;
for i:=1 to n do readln(a[i]!;
s:=suma(a,n!;
%rite(&s=&,s:*:(!;
end.


3. De alcatuit un subprogram ce determina suma elementelor pozitive
si produsul elementelor negative din a[1..10] of real de folosit
procedura.
Program P+;
type tab=array[1..10] of real;
var a:tab;
i,n:integer;
s,p:real;
procedure suma(var :tab; n:integer; var sum:real!;
var i:integer;
begin
s:=0;
for i:=1 to n do
if [i],0 t-en sum:=sum"[i];
end;
procedure prod(var :tab; n:integer; var prod:real!;
var i:integer;
begin
p:=1;
for i:=1 to n do
if [i].0 t-en prod:=prod/[i];
end;
begin#main$
%rite(&n=&!; readln(n!;
%rite(&dati elementele tabloului:&!;
for i:=1 to n do readln(a[i]!;
suma(a,n,s!;
%rite(&s=&,s:*:(!;
prod(a,n,p!;
%rite(&p=&,p:*:(!;
end.

. De creat un subprogram ce determina perimetrul minim si locul lui
in tabloul a[1..10] of real.
Program P0;
type tab=array[1..10] of real;
var a:tab;
locul,i,n:integer;
min:real;
function minim(var :tab; 1:integer!:real;
var 2:integer;
begin
min:=[1]; locul:=1;
for 2:=( to 1 do begin
if [2].min t-en
begin
min:=[2]; locul:=2;
end;
end;
minim:=min;
end;
begin
%rite(&n=&!; readln(n!;
for i:=1 to n do readln(a[i]!;
min:=minim(a,n!;
%riteln(&min=&,min:*:(,&locul=&,locul!;
end.


!. De creat un subprogram.
1.de citire a unui tablou de la tastatura a unui numar intreg.
2.de afisare a continutului unui tablou de numere intregi.
3.de inlocuit elementele pare prin 0, impare prin 1.
Program P*;
type tab=array[1..10] of integer;
var a:tab;
i,1,n:integer;
procedure citire(var b:tab; var 1:integer!;
var i:integer;
begin
%rite(&1=&!; readln(1!;
%rite(&tastati&,&1&,&numere:&!;
for i:=1 to 1 do read(b[i]!;
end;
procedure afisare(var b:tab; 1:integer!;
var i:integer;
begin
%riteln(&continutul tabloului:&!;
for i:=1 to 1 do
%rite(b[i],& &!;
end;
procedure inlocuire(var :tab; n:integer!;
var i:integer;
begin
for i:=1 to n do
if [i] mod (=1 t-en [i]:=0
else [i]:=1;
end;
begin#main$
citire(a,n!;
inlocuire(a,n!;
%rite(&tabloul obtinut:&!;
afisare(a,n!;
end.