Login
Register
All Activity
Questions
Unanswered
Tags
Books
@ProAnswers
Enter your email address:
C Books Guide and List
C++ Books Guide and List
Best Java Books
C program to generate the Fibonacci series.
+2
votes
c-program
c
c-language
asked
by
Smita
Advisor
(
7,120
points)
home work questions.?? :)
ya.. please help..
2 Answers
+1
vote
Best answer
Fibonacci series: Any number in the series is obtained by adding the previous two numbers of the series.
Let f(n) be n'th term.
f(0)=0;
f(1)=1;
f(n)=f(n-1)+f(n-2); (for n>=2)
Series is as follows
0
1
1 (1+0)
2 (1+1)
3 (1+2)
5 (2+3)
8 (3+5)
13 (5+8) and so on..
*******////PROGRAM:////**********
#include<stdio.h>
int main() {
//array fib stores numbers of fibonacci series
int i, fib[25];
/////////initialized first element to 0
fib[0] = 0;
/////////initialized second element to 1
fib[1] = 1;
/////////loop to generate ten elements
for (i = 2; i < 10; i++) {
///////// i'th element of series is equal to the sum of i-1'th element and i-2'th element.
fib[i] = fib[i - 1] + fib[i - 2];
}
printf("The fibonacci series is as follows \n");
/////////print all numbers in the series
for (i = 0; i < 10; i++) {
printf("%d \n", fib[i]);
}
return 0;
}
OUTPUT:
The fibonacci series is as follows
0
1
1
2
3
5
8
13
21
34
answered
by
albertina
Geek
(
15,670
points)
edited
by
albertina
thanks a lot..!!!
0
votes
#include<stdio.h>
void main()
{
int fib,num,n1,n2;
printf("enter num value");
scanf("%d",&num);
printf("enter n1,n2 values");
scanf("%d,%d",&n1,&n2);
for(i=0;i<num;i++)
{
fib=n1+n2;
n1=n2;
n2=fib;
}
}
answered
by
Anusha
Jr Member
(
630
points)
Related questions
0
votes
1
answer
c program for Finding sum of the series
asked
by
baden
Sr Member
(
2,360
points)
c
c-program
c-language
datastructure
+1
vote
2
answers
c program to find the maximum of three numbers ?
asked
by
anonymous
c
c-program
c-language
cpp
+1
vote
1
answer
C program to implement the atoi() function
asked
by
anonymous
c
c-program
c-language
datastructure
0
votes
1
answer
In C another function used to execute the program instead of "main function"?
asked
by
anonymous
c
c-language
c-program
0
votes
1
answer
C program to check whether the given number is a palindromic number.
asked
by
Smita
Advisor
(
7,120
points)
c-program
c-language
c