Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
practica 7 ejercicio 1
//fpc 3.0.4 program HelloWorld; {----------------------------------------------------------------------------------} {----------------------------------------------------- CONST - Declaracion de constantes definidas por el usuario} const Nros = 40; {----------------------------------------------------------------------------------} {----------------------------------------------------------------------------------} {----------------------------------------------------- TYPE - Declaracion de tipos definidos por el usuario} type {----------------------RANGOS-------------------------------} rangoNros = 1 .. Nros; {----------------------VECTORS------------------------------} Tvector = array [rangoNros] of real; {----------------------------------------------------------------------------------} {----------------------------------------------------------------------------------} {--------------------------------------------------------------- VARIABLES GLOBALES} var i: rangoNros; {----------------------------------------------------------------------------------} {----------------------------------------------------------------------------------} {--------------------------------------------------------------- CARGAR VECTOR - Ingresa los valores al vector de forma aleatoria } procedure cargarVector(var v :Tvector); begin randomize; writeln; writeln('--------------------------------cargando vector--------------------------------'); writeln; for i:=1 to Nros do begin v[i]:=random(60); end; end; {--------------------------------------------------------------- RETORNAR VECTOR - Imprime en pantalla todos los valores del vector} procedure retornarVector(v:Tvector); begin writeln; writeln('-------------------------------Retornar Vector-----------------------------------'); writeln; writeln('---------------------------------------------------------------------------------------------------------------------'); for i:=1 to Nros do begin write(' | ',v[i]:3:2); end; writeln; writeln('---------------------------------------------------------------------------------------------------------------------'); writeln; end; {----------------------------------------------------------------------------------} {----------------------------------------------------------------------------------} {--------------------------------------------------------------- RETORNAR PROMEDIO - suma todos los valores y los divide por su cantidad, retorna ese valor } function retornarPromedio(v:Tvector):real; var prom:real; begin prom:=0; for i:=1 to Nros do begin prom:= v[i] + prom; end; retornarPromedio:= prom / Nros; end; {----------------------------------------------------------------------------------} {----------------------------------------------------------------------------------} {--------------------------------------------------------------- INGRESAR VALORES - Ingresa dos valores para tomar rango de valores } procedure ingresarValores(var valor1:real; var valor2: real); begin writeln; writeln('--------------------------------ingresando valores-------------------------------- '); writeln; while valor1 >= valor2 do begin randomize; valor1 := random(30); randomize; valor2 := random(60); end; writeln('valor 1: ',valor1:3:2); writeln; writeln('valor 2: ',valor2:3:2); end; {--------------------------------------------------------------- RETORNAR VALORES - Se encarga de imprimir en pantalla todos los valores que se encuentran entre valor 1 y valor 2 ingresados en el anterior modulo de forma aleatoria} procedure retornarValores(v:Tvector;valor1,valor2:real); begin writeln; writeln('---------------------------------------------------------------------------------------------------------------------'); for i:=1 to Nros do begin if (v[i]<= valor2)and(v[i]>= valor1) then write(' | ',v[i]:3:2); end; writeln; writeln('---------------------------------------------------------------------------------------------------------------------'); writeln; end; {----------------------------------------------------------------------------------} {----------------------------------------------------------------------------------} {--------------------------------------------------------------- RETORNAR MAXIMOS - Imprime en pantalla los dos valores mas altos del vector} procedure retornarMaximos(v:Tvector;max1,max2:real;pmax1,pmax2:rangoNros); begin writeln; writeln('--------------------------------retornar maximos-------------------------------- '); writeln; for i:=1 to Nros do begin if v[i]> max1 then begin max2:=max1; max1:=v[i]; pmax2:=pmax1; pmax1:=i; end else if v[i] > max2 then begin max2:=v[i]; pmax2:=i; end; end; writeln('maximo 1: ',max1:3:2,' en la posicion ', pmax1); writeln; writeln('maximo 2: ',max2:3:2,' en la posicion ',pmax2); writeln; end; {----------------------------------------------------------------------------------} {----------------------------------------------------------------------------------} {----------------------------------------------------- PROGRAMA PRINCIPAL} var v:Tvector; valor1,valor2:real; begin //-------------A-------------// cargarVector(v); retornarVector(v); //-------------B-------------// writeln; writeln('el promedio de los valores dentro del vector es ',retornarPromedio(v):3:2); writeln; //-------------C-------------// ingresarValores(valor1,valor2); retornarValores(v,valor1,valor2); //-------------D-------------// retornarMaximos(v,0,0,1,1); end. {----------------------------------------------------------------------------------}
run
|
edit
|
history
|
help
0
practica 5 ejercicio 6
звёздное небо и подсчёт кратных звёзд
Homework 1
9
день недели по номеру дня
For6
Бассейн-8 count
practica 3 ejercicio 9
fmke
1