From 72ba0e98936d04a24773c1954837054bef8a3e70 Mon Sep 17 00:00:00 2001 From: Connor McDowell Date: Sun, 10 Mar 2024 15:53:34 -0700 Subject: size_t comments created --- Project1/Homework3.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) 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)); -- cgit v1.2.3