Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Fibonacci Numbers
SUBMITTED BY:
Guest
DATE:
Nov. 11, 2013, 4:51 p.m.
FORMAT:
C++
SIZE:
903 Bytes
Raw
Download
Tweet
HITS:
1005
Go to comments
Report
// AUTHOR : If you like this, please donate to this Bitcoin address: 19GU2ZUFgwbsXM1NSP7jM55FnDiDiN5eCr
// PURPOSE : Accept an integer number N from the user, and print out the first N Fibonacci numbers.
#include
<stdio.h>
int
main
()
{
int
n
;
// the number of Fibonacci we want to print
int
count
;
// the number of Fibonacci number printed so far. Loop Counter Variable
int
first
;
int
second
;
int
next
;
printf
(
"
\n
Please enter a number greater than 2 : "
);
scanf_s
(
"%d"
,
&
n
);
first
=
0
;
second
=
1
;
printf
(
"%5d %5d"
,
first
,
second
);
count
=
2
;
// because 2 numbers have been printed so far
while
(
count
<
n
)
{
next
=
first
+
second
;
printf
(
"%5d"
,
next
);
count
=
count
+
1
;
first
=
second
;
second
=
next
;
}
getchar
();
getchar
();
return
0
;
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus