diff --git a/fundamentos-programacion/PR3/README.md b/fundamentos-programacion/PR3/README.md index 26a901d..14d1347 100644 --- a/fundamentos-programacion/PR3/README.md +++ b/fundamentos-programacion/PR3/README.md @@ -1362,21 +1362,150 @@ end algorithm - **Ejercicio 2**: +```alg +type + tReal = record + collect: vector[10] of real; + position: integer; + end record +end type +action maxValores(in tabla: tReal) + var + max: real; + i: integer; + end var + max:= tabla.collect[1]; + for i:= 2 to tabla.position do + if tabla.collect[i] > max then + max:= tabla.collect[i]; + end if + end for + writeReal(max); +end action + +algorithm simulation + var + tabla: tReal; + end var + + tabla.collect[1]:= 1.0; + tabla.collect[2]:= 2.0; + tabla.collect[3]:= 3.0; + tabla.collect[4]:= 4.0; + tabla.collect[5]:= 5.0; + tabla.collect[6]:= 6.0; + tabla.collect[7]:= 7.0; + tabla.collect[8]:= 8.0; + tabla.collect[9]:= 9.0; + tabla.collect[10]:= 10.0; + tabla.position:= 10; + + maxValores(tabla); +end algorithm +``` + +[Solución en c](./soluciones_c/solucion2/max.c) - **Ejercicio 3**: +```alg +type + tReal = record + collect: vector[10] of real; + position: integer; + end record +end type +action minValores(in tabla: tReal) + var + min: real; + i: integer; + end var + min:= tabla.collect[1]; + for i:= 2 to tabla.position do + if tabla.collect[i] < min then + min:= tabla.collect[i]; + end if + end for + + writeReal(min); +end action + +algorithm simulation + var + tabla: tReal; + end var + + tabla.collect[1]:= 1.0; + tabla.collect[2]:= 2.0; + tabla.collect[3]:= 3.0; + tabla.collect[4]:= 4.0; + tabla.collect[5]:= 5.0; + tabla.collect[6]:= 6.0; + tabla.collect[7]:= 7.0; + tabla.collect[8]:= 8.0; + tabla.collect[9]:= 9.0; + tabla.collect[10]:= 10.0; + tabla.position:= 10; + + minValores(tabla); +end algorithm +``` + +[Solución en c](./soluciones_c/solucion3/min.c) - **Ejercicio 4**: +```alg +type + tReal = record + collect: vector[10] of real; + position: integer; + end record +end type +action sumaValores(in tabla: tReal) + var + suma: real; + i: integer; + end var + suma:= 0; + for i:= 1 to tabla.position do + suma:= suma + tabla.collect[i]; + end for + + writeReal(suma); +end action + +algorithm simulation + var + tabla: tReal; + end var + + tabla.collect[1]:= 1.0; + tabla.collect[2]:= 2.0; + tabla.collect[3]:= 3.0; + tabla.collect[4]:= 4.0; + tabla.collect[5]:= 5.0; + tabla.collect[6]:= 6.0; + tabla.collect[7]:= 7.0; + tabla.collect[8]:= 8.0; + tabla.collect[9]:= 9.0; + tabla.collect[10]:= 10.0; + tabla.position:= 10; + + sumaValores(tabla); +end algorithm +``` + +[Solución en c](./soluciones_c/solucion4/suma.c) [Volver arriba](#pr-1) diff --git a/fundamentos-programacion/PR3/soluciones_c/solucion2/max b/fundamentos-programacion/PR3/soluciones_c/solucion2/max new file mode 100755 index 0000000..e0b1409 Binary files /dev/null and b/fundamentos-programacion/PR3/soluciones_c/solucion2/max differ diff --git a/fundamentos-programacion/PR3/soluciones_c/solucion2/max.c b/fundamentos-programacion/PR3/soluciones_c/solucion2/max.c new file mode 100644 index 0000000..25d30e0 --- /dev/null +++ b/fundamentos-programacion/PR3/soluciones_c/solucion2/max.c @@ -0,0 +1,30 @@ +#include + +typedef struct +{ + float collect[10]; + int position; +} tReal; + +void maxValores(tReal *tabla) +{ + float max = tabla->collect[0]; + for (int i = 1; i < tabla->position; i++) + { + if (tabla->collect[i] > max) + { + max = tabla->collect[i]; + } + } + + printf("%f", max); +} + +int main(int argc, char **argv) +{ + tReal tabla = {{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}, 10}; + + maxValores(&tabla); + + return 0; +} \ No newline at end of file diff --git a/fundamentos-programacion/PR3/soluciones_c/solucion3/min b/fundamentos-programacion/PR3/soluciones_c/solucion3/min new file mode 100755 index 0000000..53e490f Binary files /dev/null and b/fundamentos-programacion/PR3/soluciones_c/solucion3/min differ diff --git a/fundamentos-programacion/PR3/soluciones_c/solucion3/min.c b/fundamentos-programacion/PR3/soluciones_c/solucion3/min.c new file mode 100644 index 0000000..3464475 --- /dev/null +++ b/fundamentos-programacion/PR3/soluciones_c/solucion3/min.c @@ -0,0 +1,29 @@ +#include + +typedef struct +{ + float collect[10]; + int position; +} tReal; + +void minValores(tReal *tabla) +{ + float min = tabla->collect[0]; + for (int i = 1; i < tabla->position; i++) + { + if (tabla->collect[i] < min) + { + min = tabla->collect[i]; + } + } + printf("%f", min); +} + +int main(int argc, char **argv) +{ + tReal tabla = {{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}, 10}; + + minValores(&tabla); + + return 0; +} \ No newline at end of file diff --git a/fundamentos-programacion/PR3/soluciones_c/solucion4/suma b/fundamentos-programacion/PR3/soluciones_c/solucion4/suma new file mode 100755 index 0000000..4f4232f Binary files /dev/null and b/fundamentos-programacion/PR3/soluciones_c/solucion4/suma differ diff --git a/fundamentos-programacion/PR3/soluciones_c/solucion4/suma.c b/fundamentos-programacion/PR3/soluciones_c/solucion4/suma.c new file mode 100644 index 0000000..86a60ab --- /dev/null +++ b/fundamentos-programacion/PR3/soluciones_c/solucion4/suma.c @@ -0,0 +1,26 @@ +#include + +typedef struct +{ + float collect[10]; + int position; +} tReal; + +void sumaValores(tReal *tabla) +{ + float suma = 0; + for (int i = 0; i < tabla->position; i++) + { + suma += tabla->collect[i]; + } + printf("%f", suma); +} + +int main(int argc, char **argv) +{ + tReal tabla = {{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}, 10}; + + sumaValores(&tabla); + + return 0; +} \ No newline at end of file