aboutsummaryrefslogtreecommitdiff
path: root/Homework3ReeceWarner/Homework3ReeceWarner/source.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Homework3ReeceWarner/Homework3ReeceWarner/source.cpp')
-rw-r--r--Homework3ReeceWarner/Homework3ReeceWarner/source.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/Homework3ReeceWarner/Homework3ReeceWarner/source.cpp b/Homework3ReeceWarner/Homework3ReeceWarner/source.cpp
new file mode 100644
index 0000000..7b2b0fa
--- /dev/null
+++ b/Homework3ReeceWarner/Homework3ReeceWarner/source.cpp
@@ -0,0 +1,52 @@
+//Name:Reece Warner
+//Date:1/27/2024
+//CST 116 HW #3
+
+#include <iostream>
+#include "headyhead.h"
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+int main()
+{
+ double num = 0;
+ cout << "Give me a number to find it's factorial" << endl;
+ cin >> num;
+ cout << "The factorial of " << num << " is: " << factorial(num) << endl;
+
+ cout << "Give me a number for the Fibbonacci Sequence" << endl;
+ double num2 = 0;
+ cin >> num2;
+ cout << "The Fibbonacci Sequence to " << num2 << " is \n" << fibo(num2) << endl;
+ cout << "Give me a base number" << endl;
+
+ double c ;
+ unsigned int d;
+ cin >> c;
+ cout << "\nWhat number do you wish to raise " << c << " to the power of?" << endl;
+ cin >> d;
+ cout << powrfun(c, d) << " is " << c << " raise to the power of " << d << "!" << endl;
+
+ return 0;
+}
+
+double factorial(double a)
+{
+ if (a == 0 || a == 1)
+ return 1;
+ return a * factorial(a - 1);//returning size_t would probably be a good idea here because factorials grow very quickly.
+}
+double fibo(double b)
+{
+ if (b <= 1)
+ return b;
+ return fibo(b - 1) + fibo(b - 2); //returning a size_t here would be a good idea if the input values are over 35.
+}
+double powrfun(double c, unsigned int d)
+{
+ if (d == 0)
+ return 1;
+ return c * powrfun(c, d - 1); // returning a size_t would be a good idea if either the base or the power is a large number
+} \ No newline at end of file