Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:25616f0791d2, committed 2021-04-17
- Comitter:
- johnc89
- Date:
- Sat Apr 17 12:16:56 2021 +0000
- Parent:
- 0:c87e6041f68f
- Commit message:
- Lab 2 Final modified piece of code
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c87e6041f68f -r 25616f0791d2 main.cpp --- a/main.cpp Sat Apr 17 12:14:10 2021 +0000 +++ b/main.cpp Sat Apr 17 12:16:56 2021 +0000 @@ -1,20 +1,26 @@ // Lab 2: Functions and recursive actions // John Curran T00214119 - +// we want to print using simple loops and recursive function #include "mbed.h" Serial pc(USBTX,USBRX);// serial communications int j=1, k=0, fib =0; -int N = 10 ; +int N ; -int main() { - for (int count = 0; count < N; count ++ ) { - pc.printf (" %d, ",fib); - fib = k+j; - k=j; - j=fib; +int fi(int inp) { + if (inp == 0) + return 0; + else if (inp == 1) + return 1; + else + return (fi(inp - 1) + fi (inp - 2)); + } + + int main () { + for (int i=0; i<10; i++) + pc.printf ("%d, ",fi(i)); + pc.printf("\r\n"); } - } \ No newline at end of file