From d46366ede05c1421e6fbe45253c0a770c2852768 Mon Sep 17 00:00:00 2001 From: Manuel Vergara Date: Sun, 5 May 2024 13:48:55 +0200 Subject: [PATCH] Add potencia exercise --- fundamentos-programacion/PR2/README.md | 36 ++++++++++++++++++ .../PR2/soluciones_c/solucion3/potencia | Bin 0 -> 16096 bytes .../PR2/soluciones_c/solucion3/potencia.c | 34 +++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100755 fundamentos-programacion/PR2/soluciones_c/solucion3/potencia create mode 100644 fundamentos-programacion/PR2/soluciones_c/solucion3/potencia.c diff --git a/fundamentos-programacion/PR2/README.md b/fundamentos-programacion/PR2/README.md index a683c6b..f33f1b6 100644 --- a/fundamentos-programacion/PR2/README.md +++ b/fundamentos-programacion/PR2/README.md @@ -889,6 +889,42 @@ end algorithm 3. Solución ```alg +function potencia(n: real, m: integer): real + var + i: integer; + resultado: real; + end var + + resultado:= 1.0; + + for i:= 1 to m do + resultado:= resultado * n; + end for + + return resultado; + +end function + +algorithm main + var + base, resultado: real; + exponente: integer; + end var + + writeString("[+] Introduce la base: "); + base:= readReal(); + + writeString("[+] Introduce el exponente: "); + exponente:= readInteger(); + + writeString("[i] El resultado de elevar "); + writeReal(base); + writeString(" a la potencia "); + writeInteger(exponente); + writeString(" es: "); + writeReal(potencia(base, exponente)); + +end algorithm ``` diff --git a/fundamentos-programacion/PR2/soluciones_c/solucion3/potencia b/fundamentos-programacion/PR2/soluciones_c/solucion3/potencia new file mode 100755 index 0000000000000000000000000000000000000000..2fe06649b462a92bab8374c7f76783fb99c36653 GIT binary patch literal 16096 zcmeHOZH!b`89pVf401*>^tX>slL3lg(2u%uqFJleiFFgPhuiC86h9Kl?{`-L1p(PH~W6t+sS^%3>`*=@d1xkg3{iD@Z(d< z7Viymns;$~lbwgXoPR-1uUb*acdu$+QOGtI^2KU@bN}j9&8ymzl~S@zH%$F9@S!oa zWqX%Gm|@~LjVgZFlO-PM=CYpbe>?VEqT^3Le(;}L-sn2}cJB4>@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((hrm!{SL@r2V^C7Q27fyyHV&HHFuh`got@czB1YWyw1p+qCSm{u;}2931|C2D1J; z9I%BSMpKMCgAb=+`?^TGyvIQ3e~#0oJpp^AyLb*t4PIB0u64uV00z%f0v}Uak|S_1fB) zTBw>*9wXEyl-ITW0{?mvehd}9B?zT4frJ`U*mD8|I2~>^P2Z!2EShcPyGzXc@?}7 zH01i5I!==s;P|_ke;d61V=Ck`A2-g~ar_#Dt{1gCQ+8XEB`j07yYrT7?^hryZZ(%n zX4H)(?UvhXWoS`*1(w;8wZBm6whLC)EtM;lUF}zyQg2_uah+_krM?BN&CgqQxojV@ z@DE}6kjj$R<=^IdhBABHVbs_fK@hMw5k;+tB@#sS>2Ti`_|dX z;5T$1EV1)I5<^=O>h3d;T*5rKWx|i6J4|Olsbu9)uWNS$-Li*0Qp08mr`)HKMf`P} z++VCF`^u$0r|cdIP~Fu$Hp=9)Om%GNY^DLG&3o)hk4k0_714x;ZrRfubjp={sW?Hf zpes8Cn;f{-S8!EQcQc7Z%wzlFJx^k3$Wg3>-u?DN9fhIx_=TF&>8MYT$@Ctkr0e_jN z4>f~C5j#)1Aq)Qw6f}1Eal@ZK%l=x~M@!cq74ehv{{wJz{NgXqrzcjBwNiUM@V~`h z@FqA1{Z)!hTRfC@B!KvdJOj?eN&7NyY-0bgJ+&1qv$%aW_f_J*+-JOs_y + +double potencia(double n, int m) +{ + int i; + double resultado = 1.0; + + for (i = 0; i < m; i++) + { + resultado = resultado * n; + } + + return resultado; +} + +int main() +{ + double base, resultado; + int exponente; + + printf("\n[+] Introduce la base: "); + scanf("%lf", &base); + + printf("\n[+] Introduce el exponente: "); + scanf("%d", &exponente); + + resultado = potencia(base, exponente); + + printf("\n[i] El resultado de elevar %.2f a la potencia %d es: %.2f\n\n", base, exponente, resultado); + + return 0; +}