aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWiserJ <[email protected]>2021-10-19 19:59:50 -0700
committerWiserJ <[email protected]>2021-10-19 19:59:50 -0700
commit13dfd61a5149d87048e94ae43c9a288254f3b214 (patch)
tree3339cca49b2bff684c1a7dea2bb0f330b92beb5d
parentbreak time (diff)
downloadcst116-lab3-jeffwoit-13dfd61a5149d87048e94ae43c9a288254f3b214.tar.xz
cst116-lab3-jeffwoit-13dfd61a5149d87048e94ae43c9a288254f3b214.zip
finallyHEADmaster
-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;
+