From aba41bb9090e06e4f4df1e64307400026c3831a3 Mon Sep 17 00:00:00 2001 From: Connor McDowell Date: Sat, 24 Feb 2024 15:03:59 -0800 Subject: adding fibonacci functions. added cArray, stdArray and myVector --- Project1/helper.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'Project1/helper.cpp') 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& 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& 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& 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 -- cgit v1.2.3