program ex1;
begin
clrscr;
cont:=0;
for i:= 1 to 5 do
begin
write('Informe um valor: ');
readln(a);
if a<0 then cont:=cont+1;
end;
writeln('Existem ',cont,' valores negativos.');
readkey;
end.
2. Escrever um algoritmo/programa em Pascal que escreve os números pares entre 100 e 200.
program ex2;
var i: integer;
begin
clrscr;
writeln('Os numeros pares de 100 a 200 sao: ');
for i:= 100 to 200 do
begin
if i mod 2 = 0 then
begin
write(i:8);
end;
end;
readkey;
end.
3. Escrever um algoritmo/programa em Pascal que escreve a soma dos números entre 0 e 100.
program ex3;
begin
clrscr;
soma:=0;
for i:= 0 to 100 do
begin
soma:= soma + i;
end;
writeln('A soma dos números de 0 a 100 e: ', soma);
readkey;
end.
4. Escrever um algoritmo/programa em Pascal que escreve a soma dos números pares entre 0 e 100.
program ex4;
begin
clrscr;
soma:=0;
for i:= 0 to 100 do
begin
if i mod 2 = 0 then
begin
soma:= soma + i;
end;
end;
writeln('A soma dos números pares de 0 a 100 e: ', soma);
readkey;
end.
program ex5;
begin
clrscr;
soma:=0;
for i:= 100 to 200 do
begin
if i mod 7 = 0 then
begin
soma:= soma + i;
end;
end;
writeln('A soma dos números multiplos de 7 de 100 a 200 e: ', soma);
readkey;
end.
program ex6;
begin
clrscr;
cont1:=0; cont2:=0; cont3:=0; cont4:=0;
for i:= 1 to 20 do
begin
write('Informe um valor (0-100): ');
readln(x);
if (x>=0) and (x<=25) then cont1:=cont1 + 1;
if (x>25) and (x<=50) then cont2:=cont2 + 1;
if (x>50) and (x<=75) then cont3:=cont3 + 1;
if (x>75) and (x<=100) then cont4:=cont4 + 1;
end;
writeln('No intervalo 0 - 25 existem ', cont1, ' numeros.');
writeln('No intervalo 26 - 50 existem ', cont2, ' numeros.');
writeln('No intervalo 51 - 75 existem ', cont3, ' numeros.');
writeln('No intervalo 76 - 100 existem ', cont4, ' numeros.');
readkey;
end.
program ex7;
begin
clrscr;
write('Informe um numero: ');
readln(x);
cont:=0;
for i:= 1 to x do
begin
if x mod i = 0 then cont:=cont + 1;
end;
writeln('O numero ', x, ' possui ', cont, ' divisores.');
readkey;
end.
program ex8;
var x, i: integer;
fat: integer;
begin
clrscr;
write('Informe um numero: ');
readln(x);
fat:=1;
for i:= 1 to x do
begin
fat:=fat * i;
end;
writeln('O factorial de ', x, ' e: ', fat);
readkey;
end.