|
|
This Program will output Fibonacci Series
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);
void main()
{
int n;
clrscr();
printf("Enter Number (n): ");
scanf("%d", &n);
printf("Fibonacci Series of %d Number: ", n);
fibonacci(n);
getch();
}
void fibonacci(int n)
{
int i;
double first = 0, second = 1;
int temp;
for (i = 0; i < n; ++i)
{
printf("%.0lf, ", first);
temp = second;
second += first;
first = temp;
}
}
|
IP Logged
|
I am a Lazy Coder. |