Mostrando postagens com marcador Função. Mostrar todas as postagens
Mostrando postagens com marcador Função. Mostrar todas as postagens

domingo, 6 de fevereiro de 2011

Ordem crescente de 3 números

program ordem_crescente;
uses crt;
 procedure crescente (var a, b, c: integer);
 begin
   if (a<b) and (a<c) and (b<c) then writeln ('Ordem crescente:',a,',',b,',',c)
   else
    if (a<b) and (a<c) and (c<b) then writeln ('Ordem crescente:',a,',',c,',',b)
    else
     if (b<a) and (b<c) and (a<c) then writeln ('Ordem crescente:',b,',',a,',',c)
     else
      if (b<a) and (b<c) and (c<a) then writeln ('Ordem crescente:',b,',',c,',',a)
      else
       if (c<a) and (c<b) and (a<b) then writeln ('Ordem crescente:',c,',',a,',',b)
       else
        if (c<a) and (c<b) and (b<a) then writeln ('Ordem crescente:',c,',',b,',',a)
   end;
   var x, y, z: integer;
   begin
     clrscr;
     writeln ('Digite os numeros');
     readln (x, y, z);
     writeln ('Os numeros digitados sao:', x,',', y,',', z);
     crescente(x,y,z);
     readkey;
   end.

Médias diversas

PROGRAM NOTAS;
USES CRT;
  FUNCTION MEDIA (N1,N2,N3:REAL):REAL;
  VAR LETRA:CHAR;
  BEGIN
    IF (LETRA ='A') THEN  MEDIA :=  N1+N2+N3/3
     ELSE IF (LETRA = 'P') THEN MEDIA := (N1*5)+(N2*3)+(N3*2)/10
      ELSE IF (LETRA = 'H') THEN MEDIA:=10;
  END;
  VAR NOTA1, NOTA2, NOTA3:REAL;
      LETRA: CHAR;
   BEGIN
     CLRSCR;
     WRITELN ('DIGITE AS NOTAS DO ALUNO');
     READLN (NOTA1, NOTA2, NOTA3);
     WRITELN ('DIGITE A LETRA PARA O CALCULO DA MEDIA');
     WRITELN ('A: ARITMETICA, P: PONDERADA, H: HARMONICA');
     READLN (LETRA);
     WRITELN ('MEDIA',MEDIA(NOTA1,NOTA2,NOTA3):5:2);
     READKEY;
   END.