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 2604ca9

Browse files
ThanksTM
1 parent fc4645b commit 2604ca9

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

‎fibonacci.c‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*Using loops*/
2+
3+
#include<stdio.h>
4+
5+
int main()
6+
{
7+
int n, first = 0, second = 1, next, c;
8+
9+
printf("Enter the number of terms\n");
10+
scanf("%d",&n);
11+
12+
printf("First %d terms of Fibonacci series are :-\n",n);
13+
14+
for ( c = 0 ; c < n ; c++ )
15+
{
16+
if ( c <= 1 )
17+
next = c;
18+
else
19+
{
20+
next = first + second;
21+
first = second;
22+
second = next;
23+
}
24+
printf("%d\n",next);
25+
}
26+
27+
return 0;
28+
}
29+
30+
31+
32+
2. using recursion
33+
34+
#include<stdio.h>
35+
36+
int Fibonacci(int);
37+
38+
main()
39+
{
40+
int n, i = 0, c;
41+
42+
scanf("%d",&n);
43+
44+
printf("Fibonacci series\n");
45+
46+
for ( c = 1 ; c <= n ; c++ )
47+
{
48+
printf("%d\n", Fibonacci(i));
49+
i++;
50+
}
51+
52+
return 0;
53+
}
54+
55+
int Fibonacci(int n)
56+
{
57+
if ( n == 0 )
58+
return 0;
59+
else if ( n == 1 )
60+
return 1;
61+
else
62+
return ( Fibonacci(n-1) + Fibonacci(n-2) );
63+
}

0 commit comments

Comments
(0)

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