aboutsummaryrefslogtreecommitdiff
path: root/Project1/Homework3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Project1/Homework3.cpp')
-rw-r--r--Project1/Homework3.cpp54
1 files changed, 54 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