Advertisement
paulogp

Calculo do maximo e minimo (v. 1.0.1)

Aug 7th, 2011
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.12 KB | None | 0 0
  1. { paulogp }
  2. { mac os 7 }
  3. program Ada18p;
  4.  
  5. uses
  6.     MemTypes, QuickDraw, OSIntf;
  7.  
  8. const
  9.     MAX = 10;
  10.  
  11. type
  12.     indice = 1..MAX;
  13.     vector = array[indice] of real;
  14.  
  15. var
  16.     tecla: string;
  17.     n: indice;
  18.     vn: vector;
  19.  
  20.  
  21. procedure lenum(var n: indice);
  22. begin
  23.     repeat
  24.         writeln;
  25.         write('Introduza um número Par (n in [1;', MAX, ']): ');
  26.         readln(n);
  27.         if (n < 1) or (n > MAX) or (odd(n) = true) then
  28.         begin
  29.             writeln;
  30.             writeln('Leia com atenção o que lhe é pedido!');
  31.         end;
  32.     until (n >= 1) and (n <= MAX) and (odd(n) = false);
  33. end;
  34.  
  35. procedure constroivector(var v: vector; n: indice);
  36. var
  37.     temp: integer;
  38.  
  39. begin
  40.     temp:= 1;
  41.     while temp <= n do
  42.     begin
  43.         writeln;
  44.         write('Escreva um número real: ');
  45.         readln(v[temp]);
  46.         temp:= temp + 1;
  47.     end;
  48. end;
  49.  
  50. procedure maxminvector(v: vector; n: indice);
  51. var
  52.     i, k: Integer;
  53.     aux, maximo, minimo: real;
  54.  
  55. begin
  56.     k:= n;
  57.     clearscreen;
  58.     gotoxy(35, 2);
  59.     writeln('Tabela');
  60.     gotoxy(35, 3);
  61.     writeln('------');
  62.     writeln;
  63.     writeln;
  64.     for i:= 1 to (n div 2) do write(v[i]:2:0,' ');
  65.         write(' | ');
  66.     for i:= (n div 2) + 1 to n do write(v[i]:2:0,' ');
  67.     for i:= 1 to (n div 2) do
  68.     begin
  69.         if v[i] > v[k] then
  70.         begin
  71.             aux:= v[i];
  72.             v[i]:= v[k];
  73.             v[k]:= aux;
  74.         end;
  75.         k:= k - 1;
  76.     end;
  77.     writeln;
  78.     writeln;
  79.     for i:= 1 to (n div 2) do write(v[i]:2:0, ' ');
  80.     write(' | ');
  81.     for i:= (n div 2) + 1 to n do write(v[i]:2:0, ' ');
  82.     writeln;
  83.     writeln;
  84.     writeln;
  85.     maximo:= v[1];
  86.     minimo:= v[1];
  87.     for i:= 1 to n do
  88.     begin
  89.         if (i>=(n div 2)) and (v[i] > maximo) then maximo:= v[i] else
  90.         if v[i] < minimo then minimo:= v[i];
  91.     end;
  92.     writeln;
  93.     writeln('Máximo vector: ', maximo:3:3);
  94.     writeln;
  95.     writeln('Mínimo vector: ', minimo:3:3);
  96. end;
  97.  
  98. begin
  99.     repeat
  100.         clearscreen;
  101.         gotoxy(25, 2);
  102.         writeln('Cálculo do Máximo e Mínimo');
  103.         gotoxy(25, 3);
  104.         writeln('--------------------------');
  105.         gotoxy(34, 4);
  106.         writeln('Paulo G.P.');
  107.         writeln;
  108.         lenum(n);
  109.         constroivector(vn, n);
  110.         writeln;
  111.         maxminvector(vn, n);
  112.         writeln;
  113.         writeln;
  114.         writeln;
  115.         write('Repetir (s/n): ');
  116.         readln(tecla);
  117.         uprstring(tecla, true);
  118.     until tecla = 'N';
  119. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement