Rafael Escudero / Mbed 2 deprecated escudero_ej3

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
rescudev
Date:
Fri Mar 26 22:04:33 2021 +0000
Commit message:
Ejercicio 3

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 26 22:04:33 2021 +0000
@@ -0,0 +1,72 @@
+#include <stdio.h>
+#include "mbed.h"
+
+void pi(void)
+{
+    //Número de decimales que se expresan
+    const int n=10000;
+    //Tamaño del array y definición del resto de variables
+    const int dim =3334;
+    int i, j, k, resto, digant, nueves, aux;
+    int pi[dim+1];
+
+    //Código del algoritmo
+    for (i=1;i<= dim;i ++)
+    {
+        pi[i]=2;
+        nueves=0; 
+        digant =0;
+    } 
+    for (i=1;i<=n;i++)
+    {
+        resto=0;
+        for (j= dim;j >=1;j--)
+        {
+            aux =10*pi[j]+resto*j;
+            pi[j]= aux % (2*j-1);
+            resto=aux /(2*j-1);
+        }
+        pi[1]=resto % 10;
+        resto=resto/10;
+        if(resto==9)
+        {
+             nueves++;       
+        } 
+        else if (resto==10)
+        {
+            printf("%i", digant);
+            for (k=1;k<=nueves;k++)
+            {
+                printf ("0");
+                digant=0;
+                nueves=0;
+            } 
+        }
+        else
+        {
+            printf("%i", digant);
+            digant=resto;
+            if(nueves!=0)
+            {
+                for(k=1;k<=nueves;k ++) 
+                {
+                    printf ("9");
+                    nueves=0; 
+                }              
+            }
+        }
+     }
+     printf("%i", digant);
+}
+
+
+int main()
+{
+    while(1){
+        //Llamada a la función dentro del bucle
+        printf("\nPrimeros 10000 decimales de PI:\n\r");
+        pi();
+        printf("\n");
+        wait(1);   
+    }    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Mar 26 22:04:33 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file