{
Curso : Análise e Desenvolvimento de Sistemas
Turma : Tarde
Professor : Aka
Aluno : Lucas
Matrícula : 12200935 e
Data : 30/11/2012
Programa EP02.pas - Intercalação de Dois Vetores
Objetivo: O programa deve receber números inteiros que são alocados em dois vetores e chamar um
procedimento que intercala os dois vetores ordenados.
Descrição do Programa:
Segue as seguintes instruções:
1. Lê M e um vetor de inteiros com M elementos
2. Lê N e outro vetor com N elementos
3. Imprime os valores lidos
4. Ordena os vetores
5. Imprime os vetores após a ordenação
6. Chama o procedimento de intercalação passando os seis parâmetros
}
program ep02;
type Vetor1 = array [1..20] of integer;
type Vetor2 = array [1..40] of integer;
procedure IntercalaVetor (var a,b: Vetor1; m,n: integer;
var c: Vetor2; k: integer);
var x,y,z: integer;
begin
x:=1;
y:=1;
z:=1;
while z<=k do
begin
if (a[x] < b[y]) and (x <= m) then
begin
c[z]:= a[x];
x:= x+1;
z:= z+1;
end;
if (a[x] > b[y]) and (y <= n) then
begin
c[z]:= b[y];
y:= y+1;
z:= z+1;
end;
if a[x] = b[y] then
begin
c[z]:= b[y];
y:= y+1;
z:= z+1;
end;
if x > m then
begin
c[z]:= b[y];
y:= y+1;
z:= z+1;
end;
if (x > m) and (y = n) then
begin
c[z]:= b[y];
y:= y+1;
z:= z+1;
end;
if y > n then
begin
c[z]:= a[x];
x:= x+1;
z:= z+1;
end;
if (y > n) and (x = m) then
begin
c[z]:= a[x];
x:= x+1;
z:= z+1;
end;
end;
end;
var a,b: Vetor1; c: Vetor2;
m,n,i,j,k,aux1,aux2: integer;
begin
write ('Insira m com valor máximo de 20: ');
readln (m);
for i:=1 to m do begin
write ('Entre com a[',i,']');
readln (a[i]);
end;
write ('Insira n com valor máximo de 20: ');
readln (n);
for j:=1 to n do begin
write ('Entre com b[',j,']');
readln (b[j]);
end;
i:=1;
j:=1;
writeln ('Valores de a: ');
for i:=1 to m do
writeln (a[i]);
writeln ('Valores de b: ');
for j:=1 to n do
writeln (b[j]);
i:=1;
j:=1;
for i:= 1 to m-1 do
for j:= i+1 to m do
if a[i] > a[j] then
begin
aux1:= a[j];
a[j]:= a[i];
a[i]:= aux1;
end;
i:=1;
j:=1;
for i:=1 to n-1 do
for j:= i+1 to n do
if b[i] > b[j] then
begin
aux2:= b[j];
b[j]:= b[i];
b[i]:= aux2;
end;
i:=1;
j:=1;
writeln ('Valores de a ordenados: ');
for i:=1 to m do
writeln (a[i]);
writeln ('Valores de b ordenados: ');
for j:=1 to n do
writeln (b[j]);
k:= m+n;
writeln ('Valores de c: ');
IntercalaVetor (a,b,m,n,c,k);
i:=1;
for i:=1 to k do
writeln (c[i]);
end.
Mostrando postagens com marcador Pascal. Mostrar todas as postagens
Mostrando postagens com marcador Pascal. Mostrar todas as postagens
sexta-feira, 29 de maio de 2015
Programa em Pascal que calcula datas
{
Curso : An lise e Desenvolvimento de Sistemas
Turma : Tarde
Professor : Aka
Aluno : Lucas
Matr¡cula : 12200935
Data : 28/09/2012
Programa EP01.pas - O AmanhÆ
Objetivo: O programa recebe uma data e imprime o dia seguinte.
Descri‡Æo do Programa:
A data dever estar no formato (dd mm aaaa) e ser impresso o dia seguinte
Ser feita a consistˆncia sobre a data:
1. Meses com 30 ou 31 dias
2. Fevereiro (28 ou 29 dias). Ano bissexto: ser verificado se o ano ‚ m£ltiplo
de 4 mas nÆo de 100, ou se ‚ m£ltiplo de 400.
}
program ep01;
var
dia,mes,ano,ds,ms,as,im,am4,am100,am400,ab: integer;
begin
write ('Entre com uma data: dd mm aaaa: ');
readln (dia,mes,ano);
If (dia<1) or (dia>31) or (mes<1) or (mes>12) then begin
writeln ('Data inv lida');
exit;
end;
am4:=ano-ano div 4*4;
am100:=ano-ano div 100*100;
am400:=ano-ano div 400*400;
If (am4=0) and (am100<>0) or (am400=0) then
ab:=1
Else
ab:=0;
If (mes=4) or (mes=6) or (mes=9) or (mes=11) then
im:=0;
If (mes=1) or (mes=3) or (mes=5) or (mes=7) or (mes=8) or (mes=10) or (mes=12) then
im:=1;
If (mes=2) then
im:=2;
If (mes=2) and (ab=1) then
im:=3;
If (im=2) and (dia>28) then begin
writeln ('Data inv lida');
exit;
end;
If (im=0) and (dia=31) then begin
writeln ('Data inv lida');
exit;
end;
If (im=3) and (dia>29) then begin
writeln ('Data inv lida');
exit;
end;
If (dia=28) and (im=2) or (dia=30) and (im=0) or (dia=31) and (im=1) or (dia=29) and (im=3) then
ds:=1
Else
ds:=dia+1;
If ds=1 then
ms:=mes+1
Else
ms:=mes;
If (mes=12) and (ms=13) then begin
as:=ano+1;
ms:=1;
end
Else
as:=ano;
writeln (ds,'/',ms,'/',as);
end.
Curso : An lise e Desenvolvimento de Sistemas
Turma : Tarde
Professor : Aka
Aluno : Lucas
Matr¡cula : 12200935
Data : 28/09/2012
Programa EP01.pas - O AmanhÆ
Objetivo: O programa recebe uma data e imprime o dia seguinte.
Descri‡Æo do Programa:
A data dever estar no formato (dd mm aaaa) e ser impresso o dia seguinte
Ser feita a consistˆncia sobre a data:
1. Meses com 30 ou 31 dias
2. Fevereiro (28 ou 29 dias). Ano bissexto: ser verificado se o ano ‚ m£ltiplo
de 4 mas nÆo de 100, ou se ‚ m£ltiplo de 400.
}
program ep01;
var
dia,mes,ano,ds,ms,as,im,am4,am100,am400,ab: integer;
begin
write ('Entre com uma data: dd mm aaaa: ');
readln (dia,mes,ano);
If (dia<1) or (dia>31) or (mes<1) or (mes>12) then begin
writeln ('Data inv lida');
exit;
end;
am4:=ano-ano div 4*4;
am100:=ano-ano div 100*100;
am400:=ano-ano div 400*400;
If (am4=0) and (am100<>0) or (am400=0) then
ab:=1
Else
ab:=0;
If (mes=4) or (mes=6) or (mes=9) or (mes=11) then
im:=0;
If (mes=1) or (mes=3) or (mes=5) or (mes=7) or (mes=8) or (mes=10) or (mes=12) then
im:=1;
If (mes=2) then
im:=2;
If (mes=2) and (ab=1) then
im:=3;
If (im=2) and (dia>28) then begin
writeln ('Data inv lida');
exit;
end;
If (im=0) and (dia=31) then begin
writeln ('Data inv lida');
exit;
end;
If (im=3) and (dia>29) then begin
writeln ('Data inv lida');
exit;
end;
If (dia=28) and (im=2) or (dia=30) and (im=0) or (dia=31) and (im=1) or (dia=29) and (im=3) then
ds:=1
Else
ds:=dia+1;
If ds=1 then
ms:=mes+1
Else
ms:=mes;
If (mes=12) and (ms=13) then begin
as:=ano+1;
ms:=1;
end
Else
as:=ano;
writeln (ds,'/',ms,'/',as);
end.
Assinar:
Postagens (Atom)