Turbo Pascal
Turbo Pascal
Probleme
Probleme
 
   
Home                 
Siruri de Caractere
Tablouri
Proceduri si Functii
Fisiere Text
Structuri Dinamice
        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 x:tab; n:integer; var sum:real);
var i:integer;
begin
  sum:=0;
  for i:=1 to n do
  sum:=sum+x[i];
 end;
begin{main}
  write('n='); readln(n);
  write('dati elementele tabloului:');
  for i:=1 to n do readln(a[i]);
  suma(a,n,s);
  write('s=',s:7:2);
end. 
           
2. Fie dat tabloul unidimensional a[1..10]of real, de determinat suma elementelor acestui tablou utilizind o functie.
Program P2;
type tab=array[1..10] of real;
var a:tab;
    i,n:integer;
    s:real;
function suma(x:tab; n:integer):real;
var i:integer;
    z:real;
begin
  z:=0;
  for i:=1 to n do
  z:=z+x[i];
  suma:=z;
 end;
begin{main}
  write('n='); readln(n);
  write('dati elementele tabloului:');
  for i:=1 to n do readln(a[i]);
  s:=suma(a,n);
  write('s=',s:5:2);
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 P3;
type tab=array[1..10] of real;
var a:tab;
    i,n:integer;
    s,p:real;
procedure suma(var x:tab; n:integer; var sum:real);
var i:integer;
begin
  s:=0;
  for i:=1 to n do
  if x[i]>0 then sum:=sum+x[i];
 end;
procedure prod(var x:tab; n:integer; var prod:real);
var i:integer;
begin
  p:=1;
  for i:=1 to n do
  if x[i]<0 then prod:=prod*x[i];
 end;
begin{main}
  write('n='); readln(n);
  write('dati elementele tabloului:');
  for i:=1 to n do readln(a[i]);
  suma(a,n,s);
  write('s=',s:5:2);
  prod(a,n,p);
  write('p=',p:5:2);
end. 

 

4. De creat un subprogram ce determina perimetrul minim si locul lui in tabloul a[1..10] of real.

Program P4;
type tab=array[1..10] of real;
var a:tab;
    locul,i,n:integer;
    min:real;
function minim(var x:tab; k:integer):real;
var j:integer;
begin
  min:=x[1]; locul:=1;
  for j:=2 to k do begin
      if x[j]<min then
         begin
         min:=x[j]; locul:=j;
      end;
    end;
  minim:=min;
 end;
begin
  write('n='); readln(n);
  for i:=1 to n do readln(a[i]);
  min:=minim(a,n);
  writeln('min=',min:5:2,'locul=',locul);
end.
                       

 

5. 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 P5;
type tab=array[1..10] of integer;
var a:tab;
i,k,n:integer;
procedure citire(var b:tab; var k:integer);
var i:integer;
begin
write('k='); readln(k);
write('tastati','k','numere:');
for i:=1 to k do read(b[i]);
end;
procedure afisare(var b:tab; k:integer);
var i:integer;
begin
writeln('continutul tabloului:');
for i:=1 to k do
write(b[i],' ');
end;
procedure inlocuire(var x:tab; n:integer);
var i:integer;
begin
for i:=1 to n do
if x[i] mod 2=1 then x[i]:=0
else x[i]:=1;
end;
begin{main}
citire(a,n);
inlocuire(a,n);
write('tabloul obtinut:');
afisare(a,n);
end.

 

 

 

 

 

Home