aboutsummaryrefslogtreecommitdiff
path: root/Project1/helper.cpp
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-02-24 15:03:59 -0800
committerConnor McDowell <[email protected]>2024-02-24 15:03:59 -0800
commitaba41bb9090e06e4f4df1e64307400026c3831a3 (patch)
tree6f077e697c61ebda0e01dabfdd5cbc3081c628c7 /Project1/helper.cpp
parentscreenshots taken to be added to lab, fibonacci array created (diff)
downloadlab-01-connormcdowell275-aba41bb9090e06e4f4df1e64307400026c3831a3.tar.xz
lab-01-connormcdowell275-aba41bb9090e06e4f4df1e64307400026c3831a3.zip
adding fibonacci functions. added cArray, stdArray and myVector
Diffstat (limited to 'Project1/helper.cpp')
-rw-r--r--Project1/helper.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/Project1/helper.cpp b/Project1/helper.cpp
index a90fc36..48a04cd 100644
--- a/Project1/helper.cpp
+++ b/Project1/helper.cpp
@@ -47,14 +47,51 @@ void Print(const std::list<int>& myList)
void Fibonacci(int(&cArray)[SIZE])
{
+ int y = 0;
+ cout << "enter the last element of the Fibonacci sequence you would like to see: ";
+ cin >> y;
cArray[0] = 0;
cArray[1] = 1;
- for (int i = 2; i < SIZE; i++)
+ for (int i = 2; i < y; i++)
{
cArray[i] = cArray[i - 1] + cArray[i - 2];
}
- for (int i = 0; i < SIZE; i++)
+ for (int i = 0; i < y; i++)
{
cout << cArray[i] << " ";
}
+}
+
+void Fibonacci(std::array<int, SIZE>& stdArray)
+{
+ int y = 0;
+ cout << "enter the last element of the Fibonacci sequence you would like to see: ";
+ cin >> y;
+ stdArray[0] = 0;
+ stdArray[1] = 1;
+ for (int i = 2; i < y; i++)
+ {
+ stdArray[i] = stdArray[i - 1] + stdArray[i - 2];
+ }
+ for (int i = 0; i < y; i++)
+ {
+ cout << stdArray[i] << " ";
+ }
+}
+
+void Fibonacci(std::vector<int>& myVector)
+{
+ int y = 0;
+ cout << "enter the last element of the Fibonacci sequence you would like to see: ";
+ cin >> y;
+ myVector[0] = 0;
+ myVector[1] = 1;
+ for (int i = 2; i < y; i++)
+ {
+ myVector[i] = myVector[i - 1] + myVector[i - 2];
+ }
+ for (int i = 0; i < y; i++)
+ {
+ cout << myVector[i] << " ";
+ }
} \ No newline at end of file