diff options
| author | Connor McDowell <[email protected]> | 2024-02-24 15:03:59 -0800 |
|---|---|---|
| committer | Connor McDowell <[email protected]> | 2024-02-24 15:03:59 -0800 |
| commit | aba41bb9090e06e4f4df1e64307400026c3831a3 (patch) | |
| tree | 6f077e697c61ebda0e01dabfdd5cbc3081c628c7 /Project1/helper.cpp | |
| parent | screenshots taken to be added to lab, fibonacci array created (diff) | |
| download | lab-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.cpp | 41 |
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 |