Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program punto1;
- uses crt;
- type vector= array[1..50] of integer;
- var numeros: vector; opcion:integer; i:integer; salir:boolean;
- procedure cargar (var arreglo:array of integer);
- var i:integer;
- begin
- for i:=1 to length(arreglo) do
- begin
- arreglo[i]:=random(40)-20;
- end;
- end;
- Function cant_ceros (arreglo: array of integer):integer;
- var i:integer; ceros:integer;
- begin
- ceros:=0;
- for i:=1 to length(arreglo) do
- begin
- if arreglo[i]=0 then
- ceros:= ceros + 1;
- end;
- cant_ceros:= ceros;
- end;
- Function cant_positivos (arreglo: array of integer):integer;
- var i:integer; positivos:integer;
- begin
- positivos:=0;
- for i:=1 to length(arreglo) do
- begin
- if arreglo[i]>0 then
- positivos:= positivos + 1;
- end;
- cant_positivos:= positivos;
- end;
- Function cant_negativos (arreglo: array of integer):integer;
- var i:integer; negativos:integer;
- begin
- negativos:=0;
- for i:=1 to length(arreglo) do
- begin
- if arreglo[i]<0 then
- negativos:= negativos + 1;
- end;
- cant_negativos:= negativos;
- end;
- function mayor(arreglo:array of integer):integer;
- var i:integer; n_mayor:integer;
- begin
- n_mayor:=0;
- for i:=1 to length(arreglo) do
- begin
- if arreglo[i]>n_mayor then
- n_mayor:=arreglo[i];
- end;
- mayor:=n_mayor;
- end;
- function suma_impares(arreglo:array of integer):integer;
- var i:integer; impares:integer;
- begin
- impares:=0;
- for i:=1 to length(arreglo) do
- begin
- if arreglo[i] mod 2=1 then
- impares:= impares + arreglo[i];
- end;
- suma_impares:=impares;
- end;
- begin
- salir:=true;
- While (Salir) do
- begin
- writeln(' Seleccione una opción ');
- writeln('1: Cargar vector');
- writeln('2: Ver vector');
- writeln('3: Mostrar cantidad de ceros');
- writeln('4: Mostrar cantidad de positivos');
- writeln('5: Mostrar cantidad de negativos');
- writeln('6: Mostrar el mayor');
- writeln('7:Mostrar los impares');
- writeln('8: Mostrar la suma de los impares');
- writeln('0: Salir');
- readln(opcion);
- while (opcion<0) or (opcion>8) do
- begin
- writeln('Error, elija otra opción');
- readln(opcion);
- clrscr;
- end;
- case (opcion) of
- 1:begin
- clrscr;
- cargar(numeros);
- writeln('Vector cargado');
- end;
- 2:begin
- clrscr;
- for i:=1 to length(numeros) do
- write(numeros[i],', ');
- end;
- 3:begin
- clrscr;
- Writeln('Ceros: ', cant_ceros(numeros));
- end;
- 4:begin
- clrscr;
- Writeln('Positivos: ', cant_positivos(numeros));
- end;
- 5:begin
- clrscr;
- writeln('Negativos: ', cant_negativos(numeros));
- end;
- 6:begin
- clrscr;
- writeln('El mayor es: ', mayor(numeros));
- end;
- 7:begin
- clrscr;
- writeln('Los impares son: ');
- for i:=1 to length(numeros) do
- if numeros[i] mod 2=1 then
- writeln(numeros[i]);
- end;
- 8:begin
- clrscr;
- writeln('La suma de los impares es: ', suma_impares(numeros));
- end;
- 0:begin
- clrscr;
- salir:=false;
- end;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement