Advertisement
paulogp

Calculo do maximo

Aug 7th, 2011
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.32 KB | None | 0 0
  1. { paulogp }
  2. { mac os 7 }
  3. Program Ada_C02;
  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. procedure lenum(var n: indice);
  21. begin
  22.     writeln;
  23.     repeat
  24.         write('Introduza um número Inteiro (n in [1;', MAX, ']): ');
  25.         readln(n);
  26.         if (n < 1) or (n > MAX) then writeln('Leia de novo o que lhe é pedido!!!');
  27.         writeln;
  28.     until (n >= 1) and (n <= MAX);
  29. end;
  30.  
  31. procedure constroivector(var v: vector; n: indice);
  32. var
  33.     temp: integer;
  34.  
  35. begin
  36.     temp:=1;
  37.     while temp <= n do
  38.     begin
  39.         writeln;
  40.         write('Escreva um número real: ');
  41.         readln(v[temp]);
  42.         temp:= temp + 1;
  43.     end;
  44. end;
  45.  
  46. Function maxvector(v: vector; n: indice): real;
  47. var
  48.     i: integer;
  49.     j: real;
  50.  
  51. begin
  52.     j:= v[1];
  53.     for i:= 1 to n do
  54.         if v[i] > j then j:= v[i];
  55.     maxvector:= j;
  56. end;
  57.  
  58. begin
  59.     repeat
  60.         clearscreen;
  61.         gotoxy(25, 2);
  62.         writeln('Programa: Cálculo do Máximo');
  63.         gotoxy(25, 3);
  64.         writeln('---------------------------');
  65.         gotoxy(33, 4);
  66.         writeln('Paulo G.P.');
  67.         writeln;
  68.         lenum(n);
  69.         constroivector(vn, n);
  70.         writeln;
  71.         writeln;
  72.         writeln('Máximo vector: ', maxvector(vn, n):2:1);
  73.         writeln;
  74.         writeln;
  75.         write('Repetir (S/N): ');
  76.         readln(tecla);
  77.         uprstring(tecla, true);
  78.     until tecla = 'N';
  79. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement