25.03.2015 Views

Lista 02 - DCC/UFMG

Lista 02 - DCC/UFMG

Lista 02 - DCC/UFMG

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

13) Construa um algoritmo em PORTUGOL que dado quatro valores, A, B, C e D, o<br />

algoritmo imprima o maior e o menor valor.<br />

algoritmo L2P13;<br />

var<br />

inteiro: A, B, C, D;<br />

início<br />

leia(A,B,C,D);<br />

se ( A > B ) e ( A > C ) e ( A > D ) então<br />

imprima("Maior: ",A);<br />

fim-se<br />

se ( B > A ) e ( B > C ) e ( B > D ) então<br />

imprima("Maior: ",B);<br />

fim-se<br />

se ( C > A ) e ( C > B ) e ( C > D ) então<br />

imprima("Maior: ",C);<br />

fim-se<br />

se ( D > A ) e ( D > B ) e ( D > C ) então<br />

imprima("Maior: ",D);<br />

fim-se<br />

se ( A < B ) e ( A < C ) e ( A < D ) então<br />

imprima("Menor: ",A);<br />

fim-se<br />

se ( B < A ) e ( B < C ) e ( B < D ) então<br />

imprima("Menor: ",B);<br />

fim-se<br />

se ( C < A ) e ( C < B ) e ( C < D ) então<br />

imprima("Menor: ",C);<br />

fim-se<br />

se ( D < A ) e ( D < B ) e ( D < C ) então<br />

imprima("Menor: ",D);<br />

fim-se<br />

fim<br />

program l2p13;<br />

var<br />

A, B, C, D: integer;<br />

begin<br />

write('Entre com quatro valores: ');<br />

readLn(A,B,C,D);<br />

if ( A > B ) and ( A > C ) and ( A > D ) then<br />

writeLn('Maior: ',A);<br />

if ( B > A ) and ( B > C ) and ( B > D ) then<br />

writeLn('Maior: ',B);<br />

if ( C > A ) and ( C > B ) and ( C > D ) then<br />

writeLn('Maior: ',C);<br />

if ( D > A ) and ( D > B ) and ( D > C ) then<br />

writeLn('Maior: ',D);<br />

if ( A < B ) and ( A < C ) and ( A < D ) then<br />

writeLn('Menor: ',A);<br />

if ( B < A ) and ( B < C ) and ( B < D ) then<br />

writeLn('Menor: ',B);<br />

if ( C < A ) and ( C < B ) and ( C < D ) then<br />

writeLn('Menor: ',C);<br />

if ( D < A ) and ( D < B ) and ( D < C ) then<br />

writeLn('Menor: ',D);<br />

end.<br />

<strong>UFMG</strong> – ICEx – <strong>DCC</strong> – Programação de Computadores – 2º. Sem 2005 – David Menoti 13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!