vettori e matrici

esci algebraturbo.htm

 

PROGRAM matri16;
(* caricamento valori STRINGA in vettore e ricerca LINEARE elemento *)
(* valori compaiono anche duplicati *)
uses crt;
var h,n,k,t:integer;
v:array[1..50] of string[20];
w:array[1..50] of string[20];
q:array[1..50] of integer;
d:string[20];

begin
clrscr;
write('scrivi numero elementi < 50 ');readln(n);
writeln('scrivi elementi del vettore :nomi ');
for h:=1 to n do
begin
write('elemento n.',h,' = ' );readln(v[h]);
end;

K:=1;
write('scrivi elemento da cercare in vettore ');readln(d);
for h:=1 to n do
if v[h]=d then
begin
w[k]:=v[h];
q[k]:=h;
k:=k+1;
end;

t:=0;
writeln('stampa risultato ricerca');
for h:=1 to n do
if w[h]=d then
begin
writeln(d,' elemento presente nel vettore al posto ',q[h]);
t:=t+1;
end;

if t=0 then writeln(' elemento non presente in vettore');

writeln;
writeln('premiINVIO');
readln;
end.