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.
Diff: main.cpp
- Revision:
- 1:a388472c17f4
- Parent:
- 0:3f1c5a906dc0
diff -r 3f1c5a906dc0 -r a388472c17f4 main.cpp
--- a/main.cpp Sat Apr 17 10:23:22 2021 +0000
+++ b/main.cpp Sat Apr 17 11:13:51 2021 +0000
@@ -2,14 +2,24 @@
#include "mbed.h"
-void Fibanocci(int N){
+int Fibanocci_recursion(int n)
+{
+ if (n <= 1)
+ return n;
+ else
+ return Fibanocci_recursion(n-1) + Fibanocci_recursion(n-2);
+}
+
+
+void Fibanocci(int N)
+{
int i = 0;
//Tried up to 50, but at 47, unsigned int number is overflowed showing negative result
-// so I changed to long long
+// so I changed to long long
unsigned long long j = 1;
unsigned long long k = 0;
unsigned long long fib = 0;
- while (i<=N){
+ while (i<=N) {
printf("Fibanocci(%d) = %lld\n", i, fib);
fib = j + k;
j = k;
@@ -22,10 +32,14 @@
{
Fibanocci(50);
-
-
+
+//recursion function is soo computational complicated, so when reached over 30, it takes ages to compute
+ for(int x = 0; x <40; x++) {
+ int f = Fibanocci_recursion(x);
+ printf("Fibanocci_recursion(%d) = %d\n", x, f);
+ }
while(true) {
-
+ wait(1);
}