diff options
Diffstat (limited to 'Project1/Homework3.cpp')
| -rw-r--r-- | Project1/Homework3.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Project1/Homework3.cpp b/Project1/Homework3.cpp index 9d0f11e..1555419 100644 --- a/Project1/Homework3.cpp +++ b/Project1/Homework3.cpp @@ -40,6 +40,9 @@ int main() int factorial(int f) { + // factorial equations with numbers as requested by the input cout statements will always be positive, and can get quite large. + // in this case, an unsigned number can be used as the sign of the number will always be positive and to prevent the memory from stacking up, + // using a size_t (unsigned long long) will prevent that, and in terms of efficiency, it is as fast as the int type. if (f == 0 || f == 1) return 1; long calc = f * factorial(f - 1); @@ -48,6 +51,9 @@ int factorial(int f) int fibonacci(int n) { + // for the same as above, though the int type is incredibly fast, the fibonacci sequence is all positive numbers, thus they dont need a sign + // and for above as well, the fibonacci sequence gets quite large incredibly quickly, and using a size_t will prevent hitting the number cap that + // int types have. int a = 0, b = 1, c, i; if (n == 0 || n == 1) { @@ -61,6 +67,8 @@ int fibonacci(int n) int powerfunc(int m, int p) { + // though a sign can be useful in higher level applications for powers, in all actuality, a negative number only needs a sign on odd power values. + // for the even powers conversion to a size_t will reduce space and increase the number count. if(p != 0) { return(m * powerfunc(m, p - 1)); |