aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CST116F2021-Lab3/CST116F2021-Lab3.cpp42
1 files changed, 18 insertions, 24 deletions
diff --git a/CST116F2021-Lab3/CST116F2021-Lab3.cpp b/CST116F2021-Lab3/CST116F2021-Lab3.cpp
index 7bdb00e..49d9184 100644
--- a/CST116F2021-Lab3/CST116F2021-Lab3.cpp
+++ b/CST116F2021-Lab3/CST116F2021-Lab3.cpp
@@ -9,38 +9,32 @@ int main()
{
//p.192
- int input = 0, prev = 1, next = 1;
+ int input = 0, seq1 = 0, seq2 = 0, seq3 = 0;
cout << "Please enter your ending number: ";
cin >> input;
- if (input == 1)
- cout << prev << ' ' << next;
- else
- {
- cout << prev << " " << next << ' ';
- while (next <= input)
- {
- next += prev;
- cout << next << ' ';
-
- if (prev == 1)
- {
- next += prev;
- cout << next << ' ';
- prev += prev;
- }
- else
- {
- next += prev;
- cout << next << ' ';
- prev += prev;
- }
+ cout << "1 1 ";
+ if (seq1 == 0)
+ seq1 = 1;
+ seq2 += seq1;
+ seq3 = seq1 + seq2;
+
+ while (seq3 <= input)
+ {
+ cout << seq3 << ' ';
+ seq1 = seq2;
+ seq2 = seq3;
+ seq3 = seq1 + seq2;
}
- }
+
+
+
+ return 0;
+