diff options
| author | Connor McDowell <[email protected]> | 2024-03-10 15:36:08 -0700 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-03-10 15:36:08 -0700 |
| commit | e9a3f0b5a19da2f3cf7cdcd60d76513550eb07f6 (patch) | |
| tree | 4aa57d5a44c762bb9ab0fed6550cf8cccf310ab0 /Project1 | |
| parent | funcitons written, tested, built, and debugged! assignment complete! (diff) | |
| download | homework-3-connormcdowell275-e9a3f0b5a19da2f3cf7cdcd60d76513550eb07f6.tar.xz homework-3-connormcdowell275-e9a3f0b5a19da2f3cf7cdcd60d76513550eb07f6.zip | |
made fibonacci(int n) and powerfunc(int m, int n) recursive
Diffstat (limited to 'Project1')
| -rw-r--r-- | Project1/Homework3.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/Project1/Homework3.cpp b/Project1/Homework3.cpp index 812f88b..9d0f11e 100644 --- a/Project1/Homework3.cpp +++ b/Project1/Homework3.cpp @@ -49,24 +49,24 @@ int factorial(int f) int fibonacci(int n) { int a = 0, b = 1, c, i; - if (n == 0) - return a; - for (i = 2; i <= n; i++) + if (n == 0 || n == 1) { - c = a + b; - a = b; - b = c; + return n; + } + else + { + return(fibonacci(n - 1) + fibonacci(n - 2)); } - return b; } int powerfunc(int m, int p) { - double t = 1; - - for (int k = 1; k <= p; k++) - t = t * m; - - - return t; + if(p != 0) + { + return(m * powerfunc(m, p - 1)); + } + else + { + return 1; + } }
\ No newline at end of file |