Académique Documents
Professionnel Documents
Culture Documents
Pascal
Estruturas de Repetio
Estruturas de Controle
z
z
z
y
y
y
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
Estruturas de Repetio
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
Estrutura While-do
z
z
z
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
Exemplo -
Somar nmeros de 1 a N
programa soma
inicio
leia(N)
soma 0
num 1
Enquanto (Num <= N) faa
inicio
soma soma + num
num num + 1
fim
escreva(soma)
Obs:
fim
Se N = 1, soma = 1, 1 iterao
Se N < 1, soma = 0, 0 iterao
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
Estrutura de Repetio
(Teste no Final)
Formas de Representao no Algoritmo
Estrutura Repetio
Repeat-until
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
Estrutura Repeat-until
z
z
z
10
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
Estrutura de Repetio
(Contada)
z
z
z
z
y
y
12
13
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
For-downto
14
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
16
17
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
z
y
18
program TESTE1;
uses crt;
var ANO : integer; SEXO : char;
begin
clrscr;
write(Entre com o SEXO: ');
readln(SEXO);
while ((SEXO<>'F') and (SEXO<>'M') and
(SEXO<>'f') and (SEXO<>'m')) do
begin
gotoxy(7,2); writeln ('ERRO!!!');
gotoxy(7,1); readln(SEXO);
end;
gotoxy(7,2);
writeln('
');
write(Entre com o ANO: ');
readln(ANO); writeln;
writeln('':14,'SAIDA');
writeln('ANO = ',ANO:4,'':12,'SEXO:
',SEXO);
readln;
end.
19
10
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
z
y
20
program ACUMULA1;
uses crt;
var NUMERO,CONT:integer;
begin
clrscr;
CONT:=0;
write('FORNECA O NUMERO: ');
readln(NUMERO);
while (NUMERO <> -1) do
begin
if (NUMERO > 8) then CONT:=CONT+1;
write('FORNECA O NUMERO: ');
readln(NUMERO);
end;
writeln('QUANTIDADE DE NUMEROS MAIORES
QUE 8: ',CONT);
readln;
readln;
end.
21
11
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
z
y
22
program ACUMULA2;
uses crt;
var NUMERO, CONT, CONT2 : integer;
begin
clrscr;
CONT2:=0;
CONT:=0;
write('FORNECA O NUMERO: ');
readln(NUMERO);
23
12
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
z
y
x
x
25
13
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
program TESTE2;
var N,ALTAS,BAIXAS,PONTOS:integer;
begin
N:=0;
ALTAS:=0;
BAIXAS:=0;
writeln('FORNECA OS PONTOS OBTIDOS');
readln(PONTOS);
while (PONTOS <= 150) do
begin
if (PONTOS >=) 100
then ALTAS:=ALTAS+1
26
else
14
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
z
y
1 3 5
99
S = + + + ... +
1 2 3
50
28
program TESTE4;
uses crt;
var N,D: integer;
S:real;
begin
clrscr;
S:=0;
N:=1;
D:=1;
repeat
S:=S+(N/D);
N:=N+2;
D:=D+1;
until (D = 50);
writeln('VALOR DA SERIE: ',S:5:2);
readln;readln;
end.
29
15
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
z
y
30
program TESTE5;
uses crt;
var
PENULT,ULT,SOMA:integer;
begin
clrscr;
PENULT:=0;
ULT:=1;
write(PENULT,',',ULT,',');
repeat
SOMA:=PENULT+ULT;
write(SOMA,',');
PENULT:=ULT;
ULT:=SOMA
until (SOMA > 5000);
readln;readln;
end.
31
16
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
z
y
32
program TESTE6;
uses crt;
var
N,I:integer;
S,X:real;
Begin {Inicio do Programa}
clrscr;
write('Forneca o numero de notas: ');
readln(N);
writeln;{pula uma linha}
S:=0;
for I:=1 to N do
begin
write('Forneca a ',I:1,'a. nota: ');
readln(X);
S:=S+X;
end;
writeln('Media: ',S/N:5:2);
readln; readln;
end.
33
17
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
z
y
34
program TESTE7;
uses crt;
var
N,I:integer;
FAT:real;
begin
clrscr;
write('Forneca um numero inteiro
maior ou igual a zero:');
readln(N);
writeln;
FAT:=1;
35
18
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
for I:=1 to N do
begin
FAT:=FAT*I;
end;
writeln('Fatorial: ',FAT:5:2);
readln;
readln;
end.
36
z
y
i!
i
37
19
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
program REPETE1;
uses crt;
var
N,K,SOMA,PROD,MULT:integer;
begin
clrscr;
write('FORNECA O VALOR DE N: ');
readln(N);
SOMA:=0;
38
for k:=1 to N do
begin
PROD:=1;
for MULT:=1 to K do
PROD:=PROD*MULT;
SOMA:= SOMA+PROD;
end;
writeln('RESULTADO DA SOMATORIA:
,SOMA);
readln;
readln;
end.
39
20
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com
40
21
Printed
PDF created
with FinePrint
with pdfFactory
- purchase
trial at
version
www.fineprint.com
www.pdffactory.com