From 705eb312f4233f8cc37fc4af318c6f328f0de5c3 Mon Sep 17 00:00:00 2001 From: Manuel Vergara Date: Wed, 22 May 2024 20:18:58 +0200 Subject: [PATCH] Update PR3 --- fundamentos-programacion/PR3/README.md | 129 ++++++++++++++++++ .../PR3/soluciones_c/solucion2/max | Bin 0 -> 16048 bytes .../PR3/soluciones_c/solucion2/max.c | 30 ++++ .../PR3/soluciones_c/solucion3/min | Bin 0 -> 16048 bytes .../PR3/soluciones_c/solucion3/min.c | 29 ++++ .../PR3/soluciones_c/solucion4/suma | Bin 0 -> 16048 bytes .../PR3/soluciones_c/solucion4/suma.c | 26 ++++ 7 files changed, 214 insertions(+) create mode 100755 fundamentos-programacion/PR3/soluciones_c/solucion2/max create mode 100644 fundamentos-programacion/PR3/soluciones_c/solucion2/max.c create mode 100755 fundamentos-programacion/PR3/soluciones_c/solucion3/min create mode 100644 fundamentos-programacion/PR3/soluciones_c/solucion3/min.c create mode 100755 fundamentos-programacion/PR3/soluciones_c/solucion4/suma create mode 100644 fundamentos-programacion/PR3/soluciones_c/solucion4/suma.c 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 0000000000000000000000000000000000000000..e0b1409b0d2dbf7456aa7a5a450b43f10449772f GIT binary patch literal 16048 zcmeHOYitzP6~4RJ!6d*M0*Ns#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Py;= zc;KEVsz%iI+ASa5@Zc(1pB2D`vuERlqX&WybO35@G{_Kz{`M_0WSky2D}V-8TemjK-K}ux#heeo{Nc$^T7r%E4_W2>N7KJa5*7+Xb`tT*!(k1VBJ+$;zw*QlLIS;P>zXq}n z++AS*%GH-&y`OO70`!-$tR_dhWZC5KWvMn6h|0H9`&&#fQKzMt;I@=dXfEQTuIcA+5bA{=Mo!!2A=xk z_CE_=lVArBw<9&bS7&=azm;&og7TW%vdzoP~L;q=EsdlCKDMpVkt8- ztokyMWXy=>lF4C&I5Y#EW{GPuGKB6J#*Te0yTe9!PrHF7_U#AvwCwI^1C8AeMp$R7 z-o8&6J9q7EZP{h)-LYeTxXb8jY26h@gnLs!NS6HnhsFJ9{*#eJIzwk4i$=_dvd#t- zmhLGi*4M7YHtyMQo3Kjh-TBqKqM8Vy#yV5;T4Uij9fMrMUyG~7(Ll6 z$MSv#>_3oH(8h$ayA4XWMU-}jvaD1vJDfBlJwP*K-IS>LcY@&R^zhad0$ska(GQ3d%eaE|yRoPWdbpn!`!F%-aOzaVq^6Kf%L@ zr#YeMGA|SiabxcOGp&xJKsl9onWqZo*-_eepa0i6zLouC-YeMPh^L&nwCi zw{_v)gMr4bykE(DSoX`xzF4~dNF+|K|M$Vs`AfXakH_oD8{aN%DE>;k;9UrI#;Xv! z@`aOjqymW(eLjMTllEmESk3Wne`?Dqi@1GuFPbENU6HX167NJAJ5JXSS9pRu_F)(o pAN%jBE5J)e6Gr+UE4}??(*>y8*PtTSAa`Z{{}{_ji>+s literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..53e490f041dc34b5705f08063fa30d05a134a863 GIT binary patch literal 16048 zcmeHOYit}>6~4Q%6Q@mLCr#QsAQ?haB?ND5$BB}Vko9AeG0MXvHcbm$OS-HZBldb zxk4>hGoe@5oMR6=0IMUHf>W`I`58cpTTF#A_yLDjg3?1miknWJrVc>_6`u#iRg!^q zFaDPMDJb?*dm05pH2brJTgd?;=#HbVjMUm@HL`6g9_03V86}QXiYstjf#U=xxIID1 zC*_2WO`K0J*1<+1=#A^;I4`z3VM>tNAlZM}ioT!r+BvRHv#U{F-0ILuP}=(>;`q|C z$L&Eb^FD5Gy6e!+`4{B$s&&ak*T%+m$!Kjdk$Qy`AhsDguzF7=UZA=}A+H1fGI^V1)_uE*7{)$H#)QSth-4dg@prWo=eq55Qq zkWS@UILODz#}g76u zyhjY9yWce8iL{waJQh=ifeX@Y=CL>`7(P+@RsO zmUX0S62Nt;z-ORzZz5(3PD;jMeraMheM4KBTbM}9rK{V{`j5Z-Rb0-XdXN(#_Y3)+ z9-QwOPVoIec#Zk0uwxfq^h?_vp2iC0T4c<{yT{kKi?{EW95CVHopI+FCS5#@OObQT z6DQvZvR!cTG~RvjGvH^y&w!r+KLdUS{0#UR`2S|$?ds+K(vSSLN*}KL{W_)erwUfE zctJmMy6TkOk>ZADL0>Db`U;?Wg(Cl6vRu3J=VGyV%+_gQdF{%m=Ue}MjG11-;sV~%@*N<+yAJrBYt%v8|vF*%AY|GJcQUO z@mC&&kt*s$9Fnc+Lx;xo;mG*g)ip@a{K(|l$P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GX507wCPeG+)A355EnLc=xZ#e2LAruapTtjDzMV5Q0AF%v4!ez%jcoc98Th8-X2_8l~ z%?U-9d7)sK8}s&`X+^&Slv9b9d8%N69i@Hm`9H_;&Fm-hUcow7Jmt(A|7~!T6RE%S z`@ttJ&jVbI-B&3SeglU)UgJ1HXZqkp zZ~Px%amV**j;r7+rAVhB<45SrC}2TpX-}6tN6P+6ufOPmR}ow7ikEr!iCT~l@pH6W zy72G9Kx0>)uVg+f`(vcq*569V^Yn%g2vya6FcJ0z9hvH}$iRcmMzZ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..4f4232f2b7e4a7f59ee45855ad0ffc86e9ee19d9 GIT binary patch literal 16048 zcmeHOYitzP6~4RJV8UY!fy6)p8yZ?D@?aZ-fI?Y67RD6@7wncqO^3C2ZLhKqcXzh2 zqlCJmt*{&<(n>9gTDAQZsZ^0w@q|AHrL7@VCAO4|}*$K+Nn077b;T7=&< zYPFgRz09)N{*Vpu+A`*!i4|<010-G*6-wX}wpj^E4+)7kn;fSOK?D__2l2|u!MYpI zb3X;eUu-W(WJu8ZE#giJfCxHy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(`xEBu=ydC z!A1EgQ@0E5D9S&rl6{2}6y$(Mfu-W<`uMSmcEojF#3TE-%TDW($u9Q?R7+a$>r*RL zWysd$`q3(DpL$Hmc(=Vuy@UeQBlnxwk6ZD}i|hHt{yGY!`aj!wyN#h{Kd#)@|Cbi+(c(IKsb$QHuTpX!iTwi}vi>g$t{-x|j2~g0=J*@D4*NPgMqsD@xZ}^k9u%?zf5-L2 zxgP8Pq~N~+yY(Mjj#w(*qj*1__O9`-4s~VBS}l$B>ygg5VMcls3|TYR-K}-02W#C8 zGih|uYWFN6qiLfjk?xEnjHsE;WQ|C!Uv;IEeTkSEi)uBcBWP`Y+=yf{kpUx?GBX3J zI}=I9jA$;I900|k8HhAzgl2Qe2>N3fdk!|VhK=z4W&>;No1fX=(Av@jGqyh%VV%8t z^Fd|o-FKj|VV`ke&z?i!cB8$aabFk=_pX4Dtoi>>tNUZoh#67VIiQxAI|+)F)bpN# zqJef2AYGu^8v~%s+$CT{vuUF@l8Vv}f|dh_ipEn$E*py~Bndx8XEw`R-o=1j2Xg+j z9iikN14`EyB8hayx?IkU5i`3+c~(lx4kXP;C(z8;*efOMkcegal$J`HF|8++)A};$ zzF5W_aF{xCacp~uN7>ZS*iucy$O`X`WP6ns9Y~=G8_kUE`D!eaji*yH6a&6YED<3B zm--T>(yVT3C~7@vs8qGZLr0?e@*5~?6zX1O!x^LG)EEsZ2Pn*mPF3;-#nga@7 z=81xN_(-UalxI1AnXkoRqp5@NW!@<$^Gt+TLUlOhD^O?-Cw!T=3CiPC`Y&;UN5Q8# zq3AL%6bx}=?*6k`oj`$dDtwuz3g$Ub+IOG-_n6cpKb+gD>;$v(+#{B+k|z=wiPI2aR2M zzmoZ|?3a~&v2_2D2v4s6Y1rueg)j5tkxdkhZ + +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