|
|
This Program will output Fibonacci Series by Array
By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s.
e.g. 0,1,1,2,3,5,8,13,21, ...
Code:
#include<stdio.h>
#include<conio.h>
void fibonacci(int n, double *fibo);
void main()
{
int i;
int n;
double Result[200];
clrscr();
printf("Enter Number (n): ");
scanf("%d", &n);
printf("Fibonacci Series of %d Number\n", n);
fibonacci(n, Result);
for (i = 0; i < n; ++i)
{
printf("Serial: %02d Fibonacci: %.0lf\n", i + 1, Result[i]);
}
getch();
}
void fibonacci(int n, double *fibo)
{
int i;
fibo[0] = 1;
fibo[1] = 1;
for (i = 2; i < n; ++i)
{
fibo[i] = fibo[i - 2] + fibo[i - 1];
}
}
|
IP Logged
|
I am a Lazy Coder. |