diff options
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 |