![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Loops
main.cpp
- Committer:
- ciaranom
- Date:
- 2020-12-05
- Revision:
- 0:bf4a58ea00fa
File content as of revision 0:bf4a58ea00fa:
#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 } }