Loops

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
ciaranom
Date:
Sat Dec 05 16:56:14 2020 +0000
Commit message:
Loops

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
diff -r 000000000000 -r bf4a58ea00fa main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 05 16:56:14 2020 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX); // tx, rx
+float i,j,k,l, maxv; //Declare floating numbers
+
+
+
+int main() { //ini
+
+    i = 0;//counter 
+    j = 0;//First Value
+    k = 1;//Second Value
+    l = 0;//Next Value
+    maxv = 15;//Max value 
+    
+    pc.printf("\n\rThe first %.0f Fibonacci values:\n\r", maxv);
+   
+
+    pc.printf("%.0f\n\r", j); //print inital j value
+    pc.printf("%.0f\n\r", k); //print second k value
+    
+    
+    for(int i=0;i<maxv;i++)
+        { //for all the steps from 0 to the chosen maximum value 'maxv'
+            l = j+k; // Next value is the sume of the 2 selected sequencial values
+            j=k; //Sets this loops seconds value as the First value from the next loop
+            k=l; //Sets this loops Calculated 'Next Val' value as the Second value from the next loop
+            pc.printf("%.0f\n\r", l); //Prints the calculated Fibonacci for this loop
+        }
+               
+        
+        
+        }
+        
diff -r 000000000000 -r bf4a58ea00fa mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 05 16:56:14 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file