This program can generate Fibonacci series of any number:
Output:
How many number: 6
Fibonacci Series of 6 number.
0 1 1 2 3 5
Source Code:
#include <stdio.h>
#include <conio.h>
int fibo(int); //function prototype;
void main()
{
int i,n,r;
printf("How many no:");
scanf("%d",&n);
printf("Fibonacci Series of %d number:\n", n);
for(i = 0; i < n; i++)
{
r = fibo(i);
printf("%d\t",r);
}
getch();
}
int fibo(int n)
{
int r;
if(n == 0)
return 0;
else if(n == 1)
return 1;
else
{
r = fibo(n-1) + fibo(n-2);
return (r);
}
}
#include <stdio.h>
#include <conio.h>
int fibo(int); //function prototype;
void main()
{
int i,n,r;
printf("How many no:");
scanf("%d",&n);
printf("Fibonacci Series of %d number:\n", n);
for(i = 0; i < n; i++)
{
r = fibo(i);
printf("%d\t",r);
}
getch();
}
int fibo(int n)
{
int r;
if(n == 0)
return 0;
else if(n == 1)
return 1;
else
{
r = fibo(n-1) + fibo(n-2);
return (r);
}
}
Output:
How many number: 6
Fibonacci Series of 6 number.
0 1 1 2 3 5
No comments:
Post a Comment