Print a Fibonacci series
#include<stdio.h>
#include<conio.h>
int main( )
{
int n, a=1, b=1, temp;
printf("Enter the number");
scanf("%d",&n);
printf("Fibonacci series is %d %d ", a,b);
while(a+b<=n)
{
temp=a;
a=b;
b=a+temp;
printf("%d ",b);
}
return 0;
}
Output:-
Enter the number6
Fibonacci series is 1 1 2 3 5
Comments
Post a Comment