aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-01-30 11:55:11 -0800
committerConnor McDowell <[email protected]>2024-01-30 11:55:11 -0800
commitc96f06763bc5817734640f33f4fa0c92bad79132 (patch)
tree91f7fd354ae080ed85b973cea403981a2068e375
parent.cpp and .h formatted (diff)
downloadhomework-3-connormcdowell275-c96f06763bc5817734640f33f4fa0c92bad79132.tar.xz
homework-3-connormcdowell275-c96f06763bc5817734640f33f4fa0c92bad79132.zip
funcitons written, tested, built, and debugged! assignment complete!
-rw-r--r--Project1/Homework3.cpp54
-rw-r--r--Project1/header.h4
2 files changed, 58 insertions, 0 deletions
diff --git a/Project1/Homework3.cpp b/Project1/Homework3.cpp
index 598228d..812f88b 100644
--- a/Project1/Homework3.cpp
+++ b/Project1/Homework3.cpp
@@ -12,7 +12,61 @@ using std::endl;
int main()
{
+ int f = 0;
+ int n = 0;
+ int m = 0;
+ int p = 0;
+
+ // factorial section
+ cout << "Enter a whole, positive number you would like to see go through a factorial calculation: ";
+ cin >> f;
+ cout << "The factorial of: " << f << " is: " << factorial(f) << endl;
+
+ // fib section
+ cout << "Please enter a whole, positive number to see the number located at your input's position in the fibonacci sequence: ";
+ cin >> n;
+ cout << "The number: " << fibonacci(n) << " is located at the position of input: " << n << endl;
+
+ // powerfunc section
+ cout << "Please enter a whole, positive number as the base for an exponential expression: ";
+ cin >> m;
+ cout << "And now a whole, positive number as the power to apply to the number: ";
+ cin >> p;
+ cout << m << " to the " << p << " power is: " << powerfunc(m, p);
return 0;
+}
+
+int factorial(int f)
+{
+ if (f == 0 || f == 1)
+ return 1;
+ long calc = f * factorial(f - 1);
+ return calc;
+}
+
+int fibonacci(int n)
+{
+ int a = 0, b = 1, c, i;
+ if (n == 0)
+ return a;
+ for (i = 2; i <= n; i++)
+ {
+ c = a + b;
+ a = b;
+ b = c;
+ }
+ return b;
+}
+
+int powerfunc(int m, int p)
+{
+ double t = 1;
+
+ for (int k = 1; k <= p; k++)
+ t = t * m;
+
+
+ return t;
} \ No newline at end of file
diff --git a/Project1/header.h b/Project1/header.h
index 2676c51..2d10f39 100644
--- a/Project1/header.h
+++ b/Project1/header.h
@@ -1,7 +1,11 @@
#ifndef MY_HEADER_FILE_H
#define MY_HEADER_FILE_H
+int factorial(int f);
+int fibonacci(int n);
+
+int powerfunc(int m, int p);