Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e3eec75

Browse files
committed
Fibonacci series up
1 parent e29145f commit e3eec75

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

‎OOP1-Lab3/Fibonacci.cpp‎

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,38 @@
55

66
#include <iostream>
77
using namespace std;
8-
int main() {
9-
int a = 0, b = 1, sum = 0;
10-
cout << a << endl;
11-
cout << b << endl;
12-
while (b < 100) {
13-
sum = a + b;
14-
a = b;
15-
b = sum;
16-
if (b > 100) {
8+
9+
void FibonacciTo100() {
10+
int i = 1;
11+
int FibSum = 0;
12+
int FibPrev, FibPrevPrev;
13+
14+
while (!(FibSum>100)) {
15+
16+
if ((i == 1)||(i == 2)) {
17+
FibSum = 1;
18+
FibPrev = 1;
19+
FibPrevPrev = 1;
20+
21+
22+
}
23+
else {
24+
FibSum = FibPrev + FibPrevPrev;
25+
}
26+
27+
if (FibSum > 100) {
1728
break;
1829
}
19-
cout << sum << endl;
30+
31+
cout << "Now Fibonacci Number is"<< FibSum << endl;
32+
33+
FibPrevPrev = FibPrev;
34+
FibPrev = FibSum;
35+
i++;
2036
}
21-
system("pause");
37+
}
38+
int main() {
39+
FibonacciTo100();
40+
2241
return 0;
2342
}

‎OOP1-Lab3/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
2. Program to print Fibonacci series up to 100.
1111
- Hint: Fibonacci Series is 1, 1, 2, 3, 5, 8, 13, 21, ....
1212

13+
**Integer Overflow:**
14+
15+
If two number too large, the sum of them maybe to a negative number. It means the result affects the symbolic representation of the first bit.
16+
1317
3. Program to input a number and then calculate sum of its digits.
1418
- Hint: let number = 562. Then you should print 5 + 6 + 2 = 13.
1519

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /