Loops

Dependencies:   mbed

Revision:
0:bf4a58ea00fa
--- /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
+        }
+               
+        
+        
+        }
+