-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocura.pas
More file actions
58 lines (53 loc) · 1.36 KB
/
Copy pathprocura.pas
File metadata and controls
58 lines (53 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(* Exemplo de procura de um elemento inteiro positivo em uma tabela.
Primeiramente a tabela é carregada, ou seja, lida.
Testa-se a existência de valores não apropriados: nulos ou não na tabela anteriormente preenchida.
Um número negativo, ou nulo, nesta fase significa fim da lista dos números a serem pesquisados.
*)
program Procura (input, output);
label
99;
const
Zero =0;
Ultimo = 10;
Tam = 11;
type
Indice = 1..Tam;
Tabela = array[Indice] of integer;
var
Tab : Tabela;
I : integer;
Num : integer;
Achou : boolean;
begin
(* Carga da Tabela *)
for I := 1 to Ultimo do
begin
read (Tab[I]);
if Tab[I] <= Zero
then
begin
writeln ('Valor inválido', Tab[I]);
goto 99
end
end;
readln (Num);
while Num > Zero do
begin
Tab[Tam] := Num;
I := Zero;
Achou := false;
while not Achou do
begin
I := I + 1;
Achou := Tab[I] = Num
end;
if I < Tam
then
writeln ('Achei ', Num, ' na posição ', I)
else
writeln ('Não achei ', Num, ' na tabela ');
readln (Num)
end; (* do while *)
99;
end; (* De procura *)
end.