Advertisement
Guest User

Untitled

a guest
Aug 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.86 KB | None | 0 0
  1. program punto1;
  2. uses crt;
  3.  
  4. type vector= array[1..50] of integer;
  5. var numeros: vector; opcion:integer; i:integer; salir:boolean;
  6.  
  7. procedure cargar (var arreglo:array of integer);
  8. var i:integer;
  9. begin
  10.  
  11.     for i:=1 to length(arreglo) do
  12.     begin
  13.         arreglo[i]:=random(40)-20;
  14.     end;
  15. end;
  16.  
  17. Function cant_ceros (arreglo: array of integer):integer;
  18. var i:integer; ceros:integer;
  19. begin
  20.     ceros:=0;
  21.     for i:=1 to length(arreglo) do
  22.     begin
  23.         if arreglo[i]=0 then
  24.         ceros:= ceros + 1;
  25.     end;
  26. cant_ceros:= ceros;
  27. end;
  28.  
  29. Function cant_positivos (arreglo: array of integer):integer;
  30. var i:integer; positivos:integer;
  31. begin
  32.     positivos:=0;
  33.     for i:=1 to length(arreglo) do
  34.     begin
  35.         if arreglo[i]>0 then
  36.         positivos:= positivos + 1;
  37.     end;
  38. cant_positivos:= positivos;
  39. end;
  40.  
  41. Function cant_negativos (arreglo: array of integer):integer;
  42. var i:integer; negativos:integer;
  43. begin
  44.     negativos:=0;
  45.     for i:=1 to length(arreglo) do
  46.     begin
  47.         if arreglo[i]<0 then
  48.         negativos:= negativos + 1;
  49.     end;
  50. cant_negativos:= negativos;
  51. end;
  52.  
  53. function mayor(arreglo:array of integer):integer;
  54. var i:integer; n_mayor:integer;
  55. begin
  56. n_mayor:=0;
  57. for i:=1 to length(arreglo) do
  58. begin
  59.     if arreglo[i]>n_mayor then
  60.         n_mayor:=arreglo[i];
  61. end;
  62. mayor:=n_mayor;
  63. end;
  64.  
  65.  
  66.  
  67. function suma_impares(arreglo:array of integer):integer;
  68. var i:integer; impares:integer;
  69. begin
  70. impares:=0;
  71.     for i:=1 to length(arreglo) do
  72.     begin
  73.         if arreglo[i] mod 2=1 then
  74.         impares:= impares + arreglo[i];
  75.     end;
  76. suma_impares:=impares;
  77. end;
  78.    
  79. begin
  80. salir:=true;
  81. While (Salir) do
  82. begin
  83.     writeln('          Seleccione una opción      ');
  84.     writeln('1: Cargar vector');
  85.     writeln('2: Ver vector');
  86.     writeln('3: Mostrar cantidad de ceros');
  87.     writeln('4: Mostrar cantidad de positivos');
  88.     writeln('5: Mostrar cantidad de negativos');
  89.     writeln('6: Mostrar el mayor');
  90.     writeln('7:Mostrar los impares');
  91.     writeln('8: Mostrar la suma de los impares');
  92.     writeln('0: Salir');
  93.     readln(opcion);
  94.     while (opcion<0) or (opcion>8) do
  95.     begin
  96.         writeln('Error, elija otra opción');
  97.         readln(opcion);
  98.         clrscr;
  99.     end;
  100.     case (opcion) of
  101.     1:begin
  102.         clrscr;
  103.         cargar(numeros);
  104.         writeln('Vector cargado');
  105.         end;
  106.     2:begin
  107.         clrscr;
  108.         for i:=1 to length(numeros) do
  109.         write(numeros[i],', ');
  110.         end;
  111.     3:begin
  112.         clrscr;
  113.         Writeln('Ceros: ', cant_ceros(numeros));
  114.      end;
  115.     4:begin
  116.         clrscr;
  117.         Writeln('Positivos: ', cant_positivos(numeros));
  118.     end;   
  119.     5:begin
  120.         clrscr;
  121.         writeln('Negativos: ', cant_negativos(numeros));
  122.     end;   
  123.     6:begin
  124.         clrscr;
  125.         writeln('El mayor es: ', mayor(numeros));
  126.         end;
  127.     7:begin
  128.         clrscr;
  129.         writeln('Los impares son: ');
  130.         for i:=1 to length(numeros) do
  131.         if numeros[i] mod 2=1 then
  132.         writeln(numeros[i]);
  133.         end;
  134.     8:begin
  135.         clrscr;
  136.         writeln('La suma de los impares es: ', suma_impares(numeros));
  137.         end;
  138.     0:begin
  139.         clrscr;
  140.         salir:=false;
  141.     end;
  142.     end;
  143. end;
  144. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement