Advertisement
Ramiro-Pruis

Guia 5 - Ej1

Apr 6th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.31 KB | None | 0 0
  1. program G05Ej1;
  2. type
  3.   TV=array[1..15] of integer;
  4. procedure escVec(var A:TV;N:byte); //Escribe los datos en el vector
  5.  
  6. var
  7.   val:integer;
  8.   i:byte;
  9. begin
  10.   for i:=1 to N do
  11.   begin
  12.     Write('Ingrese un valor: ');readln(val);
  13.     A[i]:=val;
  14.   end;
  15. end;
  16.  
  17. function SumaVec(A:TV;N:byte):integer; //Suma los elementos del vector
  18.  
  19. var
  20.   i:byte;
  21. begin
  22.   SumaVec:=0;
  23.   for i:=1 to N do
  24.   begin
  25.     SumaVec:=SumaVec+A[i]
  26.   end;
  27. end;
  28.  
  29. procedure MaxMin(A:TV;N:byte);     //Encuentra valor max y min
  30. var
  31.   max,min:integer;
  32.   i:byte;
  33. begin
  34.   max:=0;min:=99999999;
  35.   for i:=1 to N do
  36.   begin
  37.     if A[i]>max then
  38.       max:=A[i];
  39.     if A[i]<min then
  40.       min:=A[i];
  41.   end;
  42.   writeln('Su valor maximo es ',max,' y su valor minimo ',min);
  43. end;
  44.  
  45. procedure permutar(A:TV;var B:TV;N:byte);   //Permuta los valores de A en B
  46. var
  47.   aux:integer;
  48.   i:byte;
  49. begin
  50.   aux:=A[N];
  51.   write('Valores del vector B: ');
  52.   for i:=1 to N do
  53.   begin
  54.     B[i]:=aux;
  55.     N:=N-1;
  56.     aux:=A[N];
  57.     write(B[i],' - ');
  58.   end;
  59. end;
  60.  
  61. var
  62.   VecA,VecB:TV;
  63.   N:byte;
  64. begin //Programa Principal
  65.   repeat
  66.   writeln('Ingrese cuantos valores va a ingresar <=15 ');readln(n);
  67.   until n<=15 ;
  68.   escVec(VecA,n);
  69.   writeln('Su suma es: ',SumaVec(VecA,n));
  70.   MaxMin(VecA,N);
  71.   permutar(VecA,VecB,N);
  72.   readln();
  73. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement