Update PR3

This commit is contained in:
Manuel Vergara 2024-05-22 20:18:58 +02:00
parent fbaedb6630
commit 705eb312f4
7 changed files with 214 additions and 0 deletions

View File

@ -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)

Binary file not shown.

View File

@ -0,0 +1,30 @@
#include <stdio.h>
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;
}

Binary file not shown.

View File

@ -0,0 +1,29 @@
#include <stdio.h>
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;
}

Binary file not shown.

View File

@ -0,0 +1,26 @@
#include <stdio.h>
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;
}